I am having trouble finding out how to set a directory as an argument in bash.
The directory I am trying to have as an argument is
Anywhere I try to look for an answer I see examples like dir = $1 but I cant seem to find an explanation of what this means or how to set it up so that it references my specific file location. Could anyone show me how to set up my variable for my path directory?
Adding my code for a better understanding of what im trying to do:
$1 == 'home/rrodriguez/Documents/one/'
dir = $1
touch -c $dir/*
ls -la $dir
Best How To :
touch -c "$dir"/*
ls -la "$dir"
This script takes one argument, a directory name, and touches files in that directory and then displays a directory listing. You can run it via:
bash script.sh 'home/rrodriguez/Documents/one/'
home/rrodriguez/Documents/one/ is the first argument to the script, it is assigned to
$1 in the script.
In shell, never put spaces on either side of the
= in an assignment.
I omitted the line
wc$dir/* because it wasn't clear to me what the purpose of it was.
I put double-quotes around
$dir to prevent the shell from, among other things, performing word-splitting. This would matter if
dir contains spaces.