0

I am trying to pass couple of Variables in sudo command via shell script, but it is not working.

my command works fine without the change_number variable like below

change_number=123456;
echo $profile |su - user1 -c '/tmp/server_upgrade.sh'

Not working(not able to pass variables to su command)

profile=app;
change_number=123456;
echo $profile |su - user1 -c '/tmp/server_upgrade.sh $change_number'
  • Hopefully I'm understanding your question correctly. Simply use double quotes instead of single quotes to run the command `/tmp/server_upgrade.sh 123456` with `123456` coming from your variable `change_number` – that other guy Jun 24 '21 at 18:30
  • even double quotes not working.. because while I am switching the user and calling the script – Praveen Kumar Jun 24 '21 at 18:34
  • Can you please do an experiment to help see what the problem is? Run `echo $profile |su - user1 -c '/tmp/server_upgrade.sh 123456'` and see if it does what you want. (This is NOT meant as a suggestion that you should stop using a variable: it is only a one-time experiment to see whether your script supports receiving the number as an argument) – that other guy Jun 24 '21 at 18:36
  • It is working with double quotes. For some reason when I tried yesterday it didn't worked. But thanks again for looking into it. Much appreciated. – Praveen Kumar Jun 24 '21 at 19:08

0 Answers0