Bash: Variable – filename example

Variable in bash is not particularly cool until we have a good use of it  😛

> filename="myfile.txt"
> touch $filename
> ls filename
myfile.txt

> rm $filename
> ls $filename
ls: myfile.txt: No such file or directory

> files="file1 file2" 
> touch $files
> ls $files
file1
file2

 

Bash: `type` Command

In unix, type command tells us whether a keyword is taken by the system or not. It is useful when trying to add a new custom command in the terminal and ensure that our command is not in conflict with system ones.

> type test
test is a shell builtin

> type cp
cp is /bin/cp

> type foo
-bash: type: foo: not found

# This is my custom command
> type note  
note is hashed (/Users/.../bin/note)