Reputation: 554
The parameter passed is changed when printed from inside the function
print "param: $FILEPREFIX" 1>&2; #return finyear*
func_copy $FILEPREFIX
then in function
function func_copy
{
fp=$1
print "param: $fp" 1>&2; #returns finyear.scr which is a script file name
what would i be doing wrong here
Upvotes: 0
Views: 2342
Reputation: 754730
When you invoke func_copy $FILEPREFIX
and FILEPREFIX
contains finyear*
, the shell expands the variable and then does wild-card matching, so the name finyear*
is changed to finyear.scr
in your directory. To avoid the expansion, enclose the name in double quotes:
func_copy "$FILEPREFIX"
(Using double quotes around a variable expansion is usually, but not always, a good idea.)
See the Bash manual on shell expansions for the sequence of operations in Bash. The POSIX shell (sh
) has similar rules, and Korn shell will likewise be similar — they all have a common ancestor, the Bourne shell.
Upvotes: 1