Question: Script 1 Lets do some basic scripting. Open up vim/nano/emacs/gedit to start creating your first script. The first line needs to define which shell will

Script 1

Lets do some basic scripting. Open up vim/nano/emacs/gedit to start creating your first script.

The first line needs to define which shell will be used to execute the program. Therefore, make the first line read:

#!/bin/bash

In this case,#! is a special set of characters that defines the bash shell. Any other instances of # will be treated as a comment (i.e., not parsed by the interpreter).

Next, we are going to do some simple string manipulations. This will be a simple program that accepts as input a string, and then simply outputs that string to the terminal.

Command line arguments are straightforward. $1 is the first, $2 is the second, and so on.

For instance:

#!/bin/bash

echo "Hello there $1, how are you doing today?"

would output "Hello there Erik, how are you doing today?" if I called this script as:

[user]$ bash sample_script.sh Erik

You can also pass a script a command as a parameter. For instance, if a script looked like:

#!/bin/bash

$1

and was called with:

[user]$ bash sample_script.sh pwd

The output (for me) would be: /home/fredericks

For Script 1, you need to do the following:

Create a bash script that takes in 3 command line parameters. The first parameter is your first name, the second parameter is your username for your system, and the third parameter is the command used to list the contents of a directory.

For example, it will be run as:

[user]$ sh _Script1.sh

The script must print the following output, replacing with your first name, and with a listing of the files in that directory (hint, remember the echo command):

Hello , the contents of my home directory are:

Please note that you cannot directly list these contents, but must use the command line argument. If I see you directly listing the contents of your username in your script, you will lose points for this section.

As a reminder for how to save output to a file, you can use the redirect operator (>) to redirect to a file (e.g., bash script.sh > script_output.txt)

Save the script as _Script1.sh, and the output in a text file named _Script1_Output.txt.

Please send the answer with photo

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!