Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.

Use thatthis syntax instead:

sh -c "demo.sh ARUN 24" 

IsIn your case those two arguments where passed to the shsh command, not the demo.sh script. Put them in quotes to pass them trought sh to the script.

But notice,Note the easiest way would be to make the script executable and add a hashbang (#!) line to it. The scripts would then look as follows:

#!/bin/sh name=$1 age=$2 echo $name echo $age 

Make it executable with:

chmod +x demo.sh 

And thenThen run it as follows (without the interpreter sh, the interpreter is now gathered fromtfrom the #! line):

./demo.sh ARUN 24 

Use that syntax instead:

sh -c "demo.sh ARUN 24" 

Is your case those two arguments where passed to the sh command, not the demo.sh script. Put them in quotes to pass them trought sh to the script.

But notice, the easiest way would be to make the script executable and add a hashbang (#!) line to it. The scripts would then look as follows:

#!/bin/sh name=$1 age=$2 echo $name echo $age 

Make it executable with:

chmod +x demo.sh 

And then run it as follows (without the interpreter sh, the interpreter is now gathered fromt the #! line):

./demo.sh ARUN 24 

Use this syntax instead:

sh -c "demo.sh ARUN 24" 

In your case those two arguments where passed to the sh command, not the demo.sh script. Put them in quotes to pass them trought sh to the script.

Note the easiest way would be to make the script executable and add a hashbang (#!) line to it. The scripts would then look as follows:

#!/bin/sh name=$1 age=$2 echo $name echo $age 

Make it executable with:

chmod +x demo.sh 

Then run it as follows (without the interpreter sh, the interpreter is now gathered from the #! line):

./demo.sh ARUN 24 
Source Link
chaos
  • 9.5k
  • 3
  • 39
  • 43

Use that syntax instead:

sh -c "demo.sh ARUN 24" 

Is your case those two arguments where passed to the sh command, not the demo.sh script. Put them in quotes to pass them trought sh to the script.

But notice, the easiest way would be to make the script executable and add a hashbang (#!) line to it. The scripts would then look as follows:

#!/bin/sh name=$1 age=$2 echo $name echo $age 

Make it executable with:

chmod +x demo.sh 

And then run it as follows (without the interpreter sh, the interpreter is now gathered fromt the #! line):

./demo.sh ARUN 24