I am trying to write a script that will let me get the arguments while running the script. I am able to do so with $@ in the script. But if I run the script with /*
or */*
it gives the list of all the directories in /*
or */*
.
What I want to get as a variable in the script, is the value /*
and */*
if used; instead of all directories and files within /*
, whenever the script is run.
I know that the issue is with the way linux fetches the values of what is associated with the "*". But did not find a solution for it.
Below is a sample script:
#!/bin/bash int_v=0 get_str="$@" for f in $get_str do if [ "$f" == "/*" ] || [ "$f" == "*/*" ] || [ "$f" == "/" ] || [ "$f" == "/boot" ] || [ "$f" == "/bin" ] || [ "$f" == "/root" ] || [ "$f" == "/dev" ] || [ "$f" == "/etc" ] || [ "$f" == "/sbin" ] || [ "$f" == "/home" ] || [ "$f" == "/mnt" ] || [ "$f" == "/sys" ] || [ "$f" == "/tmp" ] || [ "$f" == "/usr" ] || [ "$f" == "/var" ] || [ "$f" == "/proc" ]; then int_v=1 else int_v=0 fi echo $f done if [ $int_v == 1 ]; then echo "Cannot run it with the use of: */* or /* or /. " else echo "This script can run" fi
Also added a work around in the script: Since /*
is the root directory; I have added an if statement for /bin, /root ... This works, but the concern is with the */*
.
Anyone has an idea of how we can parse the actual variables used while running the script, rather than the output of it?
somecommand /*
means "runsomecommand
, and pass as arguments a list of files directories under/
". Your command cannot make itself special and give that command line some other meaning. You need to pass and take arguments in ways that conform to standard shell syntax, not try to somehow override it.