Originally Posted by arashi256
... so I need to be able to escape the shell expansion from within the script.
No, you can't do it inside the script at all. The problem is that the running shell is expanding the globs before the script is even run
. When you run:
...the shell first parses the line, replaces the "*" with a list of files that match the glob, and then executes the script. So the command that's actually being run is the script name plus all the files in the directory as arguments. Like this:
./test.sh file1 file2 file3 file4 etc...
You'd only get a literal "*" is if the directory is empty and nothing is matched.
The only way you can pass a raw globbing value is to escape or quote the arguments that you want to pass to the shell on the command line, or to disable globbing in the parent shell.
This is true of all shell syntax. If there's anything that's considered important by the shell on the line, it will be parsed and replaced before
the command is run, unless it's protected by quotes or backslash escapes.
Edit: BTW, once a value is stored in a variable or parameter, all the characters in the string are literal, and they will be treated as such by the script as long as you properly quote it. Only unquoted parameters are ever parsed for shell-reserved characters (unless you use a specific command option like printf's "%b" or echo's "-e" to force it to interpret them).
So your only real problem is with the initial setting of "$1", and how you quote it afterwards. How about showing us exactly
what you need to do, rather than fooling around with an example that may not reflect your actual purpose?