Solved after sudo ing to other user $1 is not availa

September 20, 2011 at 03:22:14
Specs: linux
after sudo ing to other user $1 is not available for use in the next statement in a shell script

See More: after sudo ing to other user $1 is not availa

Report •


#1
September 20, 2011 at 11:38:23
✔ Best Answer
The act of sudoing creates a new shell so the command line parameters are not transferred. Depending on how sudo is executed, the child environment is inherited from the parent. If so, before executing the sudo, try this:

export myvar=$1

Do you now see myvar after executing the sudo:

echo $myvar

In worst case, before executing the sudo, create the myvar in a file:

echo "myvar=$1" > /tmp/nails.txt

Now, you can source this after your sudo command creates a new shell:

. /tmp/nails.txt

Let me know if you have any comments or questions.


Report •

#2
September 21, 2011 at 03:53:12
hi,

Thanks for ur response. Its WorkInG


Report •

#3
September 21, 2011 at 04:39:41
Hi,

I have two scripts in serverA where one of it does ssh to serverB and runs other script over there. In this process i have scp in the second script to copy file from serverB to serverA.

I have an issue in scp'ing file from serverA to serverB.
It gives me an error :
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-with-mic,password).
lost connection


thanks in advance


Report •
Related Solutions


Ask Question