Explore BrainMass
Share

Linux: Explain the function

This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

Using the following script:

#!/bin/bash
#This is a shell script
echo $#
echo $0
echo $1
echo $2
echo $3
echo $*
name1=$1
#name2=$2
echo $name1 "is the first parameter"
echo $name2 "is the second parameter"
echo $
echo $0 "was executed with" $# "parameters on the command line."

Explain the function of each line in the script, assuming that it is executed as follows:

knoppix[knoppix]$ myscript joe mary bob

© BrainMass Inc. brainmass.com March 21, 2019, 6:32 pm ad1c9bdddf
https://brainmass.com/computer-science/algorithms/linux-explain-function-260284

Solution Preview

knoppix[knoppix]$ myscript joe mary bob

echo $#
3
This line is to print out the number of arguments. We have 3 of them, joe, mary, bob

echo $0
myscript
This line is to print our the name of the script. So it is myscript.

echo $1
joe
This line is to print out the first argument. So it is joe.

echo $2 ...

Solution Summary

The expert uses the Linus operator to explain the function.

$2.19