Scripting Flashcards
What should the first line of the script file contain
#!/bin/bash - bourne again shell a path to the shell that will be used to execute the script #!/bin/sh - bourne shell
how to check for conditional logic within a script
if [ a = b ] then #do something else #do something else fi
how to pass args to a script
./scriptFile.sh arg1 arg2
……………
scriptFile.sh contents
#!/bin/bash
echo here is the value of the first arg: $1
echo here is the value of the second arg: $2
how to stop a script execution
exit
remember scripts can have an exit or return value that is a numeric type from 1 to 255. This is useful for passing error values to the calling process. Usually a success will return 0.
how to create and use variables
pi=”pig”
echo $pi is my fav animal
#can also use let pi="pig"
#spaces are a big no-no pi = "pig" is invalid
is this valid for a variable declaration/assignment
variable = “New Variable”
It is not valid. The spaces will cause the line to error.
It should be:
variable=”New Variable”