$animal=panda $animal = panda ANIMAL=panda animal=panda animal = panda
ANIMAL=panda
and animal=panda
are valid
Also, ANIMAL=panda
and animal=panda
will set different variables: variable names are case
sensitive.
$
to print out the value of a variable? (like $VARNAME
?)
here's what setting & printing out a variable looks like:
x=2 echo $x
animal = pandado?
'animal'
with the arguments '='
and 'panda'
That's almost certainly not what you wanted to do if you typed that, but that's what it does!
FILENAME="file 1.txt" cat $FILENAMEprint out the contents of
file 1.txt
?
$ cat $FILENAME
will run `cat`
with 2
arguments: `file`
and `1.txt`
.
Always double quote your variables to prevent this:
$ cat "$FILENAME"
instead
filename
. What bash code will print out the value of filename
with 2
after it? (no spaces)
echo ${filename}2
The way to concatenate bash strings is by just putting them next to
each other. ${filename}
is another way to refer to
$filename
x=2 x="2"
there are no numbers in bash
in bash, environment variables are referred to the same way as regular
variables ($VARNAME
), but not all variables are environment variables
env | grep VARNAME
env
prints out all environment variables you have set, so you can grep its output
export VARNAME=value
you can also turn a non-environment variable into an environment variable, like this:
VARNAME=value export VARNAME
for example, when you run env
, what it's actually doing is
just printing out all its environment variables. These are the same as
the environment variables in your shell because env
inherits all the environment variables from your shell.
if you started a subprocess in a Python program, you wouldn't expect the subprocess to automatically get all of your Python's program's variables -- it's the same with bash shell variables.