Bash variable assignment question

Suppose I have a file named Stuff in the same directory as my script. Does the following assign the file Stuff to a variable?

Var="Stuff"

Why doesn't this just assign the string Stuff? Or rather how would I assign the string Stuff to a variable in this situation?

Also, what exactly is happening. Is the variable simply assigned the data in the file or does it point to the file?

My Bash book is not clear on this at all.

Yes, it assigns the string 'Stuff' to variable 'Var'.
Wether 'Var' contains a string "Stuff" or the filename (also a string) "Stuff" is no diffrence at all.

It neither points to the file, nor does it contain the file's data, it just contains the name of the file... 'Stuff.
To access the file, you'll need to work with that variable obviously...

Like:

Var=Stuff
echo -e "Filename: $Var\n-------------------"
cat $Var

In this case, cat is used to display the file's content.

However, as soon the file is located in another place, you must use either relative or absolute path location.
Eg:

Var=/home/riker/Stuff
Var=../Stuff

Both lines refer to the same location, if script is in $HOME/bin and the file in $HOME only.

Hope this helps

1 Like

Ok I get it now.

That very much helped. Thank you. I'm brand new to this :o

Welcome, also on board :slight_smile: