Linux: Using two command terminals (one as a text editor and one to test script)
ID: 3589607 • Letter: L
Question
Linux: Using two command terminals (one as a text editor and one to test script):
a. Create a bash script that takes in three command line parameters. First parameter is first name, second parameter is your username for your system, and the third parameter is the command used to list the contents of a directory. (It will be run as: [user]$ sh <lastname>_Script1.sh <first name> <username> <directory listing command>)
b. The script must print the following output, replacing <first name> with your first name, and <directory contents> with a listing of the files in that directory: Hello , <first name> the contents of my home directory are: <directory contents>
Explanation / Answer
#!/bin/bash
#As $0 will be script name. So actual command line arguments starts with $1
echo "Hello, $1 the contents of my home directory are:" # to insert firstname which is first argument
usershome=`eval echo ~$2` # to evaluate usernames home directory where username is second argument
echo `$3 $usershome` # to print users home directory contents taking third argument and users home directory
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.