When i tried to execute launch-rockets.sh file without executable permission, it failed i explicitly provided chmod +x /home/bob/launch-rockets.sh file. But inside of this script you can see it is calling create-and-launch-rocket inside the loop. When I checked the ls -lrt it shows that the create-and-launch-rocket does not have any executable permission. Please clarify this scenario ?
for mission in lunar-mission mars-mission jupiter-mission saturn-mission mercury-mission
do
bash /home/bob/create-and-launch-rocket $mission
done
ls -lrt
total 12
drwxr-xr-x 1 bob bob 4096 Apr 15 2020 media
-rw-r--r-- 1 bob bob 383 May 1 06:56 create-and-launch-rocket
-rwxrwxr-x 1 bob bob 148 May 1 06:58 launch-rockets.sh
A link to the lab is always helpful, so I can see the description of the problem. But I think in this case, calling the script through bash
will let you do it w/o setting the execute bit for the file. So it works anyway.
1 Like
Because the script is running
bash /home/bob/create-and-launch-rocket $mission
then create-and-launch-rocket
does not require execute permission. This is because what is being executed is bash
itself which is executable. bash
then reads the script and interprets the content. Here the script is simply an argument to bash
.
If instead it was
for ...
do
/home/bob/create-and-launch-rocket $mission
done
Then create-and-launch-rocket
would need execute permission because it is that which is being directly executed.
What happens when you execute a script directly is that the new program launcher first checks for execute permission, then loads the script. looks at the “shebang” (covered elsewhere in the course), then executes that program (usually bash
again, but could equally be sh
) on itself.