/bin/scripts/first.ksh
#!/bin/bash
start(){
first="$1";
echo "arg is $first"
}
/bin/scripts/second.sh
#!/bin/bash
nohup sh /bin/scripts/first.ksh start arg1 > nohup_log 2>&1 &
The argument is not picked up. What is the correct way to pass argument in the second script
CodePudding user response:
If you pass parameters, you have to use them somehow. One possibility is technically do write your script as
start(){
first="$1";
echo "arg is $first"
}
"$@"
The last line would - in your case - expand to start arg1
and therefore call your function. However it is risky to do this: Since the first parameter to your script (i.e. start) is treated as a command to be executed, the user of the script could inject any code via the parameter. This is a serious security hole.
I would at least verify the first parameter somehow, or redesign your script completely. For instance, it is unclear why you define a function, if the script isn't doing anything else than calling this function.