shell basics Flashcards
Learning to use bash and python scripting
How do you start a script?
Shabang #!
how do you tell your interpreter which scripting language you wanna use?
After the Shabang (#!) you type it in.
i.e. you can be like /bin/bash to tell it you are using bash
how to make a comment?
then write after the hash symbol
what does echo do?
echo writes arguments to standard output (1).
how do you execute a script via the terminal?
./file_name
so period then the backslash followed by file_name
how do you make a file to an executable if it is not already?
chmod 755 file_name defines who can do what with the file. 7 means read/write/execute. 6 means read/write. 5 means read/execute. 4 means read only. 3 means write/execute. 2 means write only. 1 means execute only. 0 means cant do anything.
what do variables start with?
letter or underscore and by convention their lowercase.
Except if they are environment variables then all caps.
how would you create a variable for a name.
variable_name=”Saidname”
no spaces
how do you declare a constant?
declare -r NUM1=5
how do you display the output of an algorithm? lets say 2*10 as example
echo $(( 2*10)) or num2=2 num10=10 echo $(( num2*num10))
works with numbers or variables
how can you use floating point numbers in your shell script?
you can call python in your code and assign the output to a variable to be displayed or used later
how do you call python in a bash script?
python -c “here use python”
i.e. num9= $(python -c “print 3.1+4.5”)
echo $num9
what does cat do?
prints a file or any string you pass to it.
how to create a function in a script?
function_name(){ //stuff inside the function return }
how to call a function previously declared?
simply call the function_name
how do you use the attributes (arguments) passed to a function?
use $1 or $2 or $3 ect.
it depends on how many attributes are sent to the function. but the numbers correlate with the