Under OS X, I have a bash shell script which takes a parameter (which is a folder name)
when I call:
echo "Build Starting for $1" | tee ~/MyFolder/$1/build.log
It works right. It echos the right “$1” parameter into the ~/MyFolder/$1/build.log file (which exist). However, when I call another executable and trying to make use of the $1 parameter, the parameter is always empty.
xcodebuild -configuration Release -project MyProject.xcodeproj | tee -a ~/MyFolder/$1/build.log
this creates “build.log” in “~/MyFolder” and the $1 is ignored.
Why is that? Do I need to “export” it somehow?
If you’re calling a function or another script and want the same $1, $2,.. to be available, use:
"$@"is equivalent to"$1" "$2" "$3" ..., and will thus make sure “$1” in the subprocess is the same as “$1” in the parent process.You can also assign their values to new, named variables:
and then use
$mydirin place of$1in subprocess scripts.