What will we see?

We have bash script ~/myscript shown below:
shift echo $2
We call this script:
~/myscript alpha beta gamma delta
What will we see?

We have bash script ~/myscript shown below:
shift echo $2
We call this script:
~/myscript alpha beta gamma delta
What will we see?

A.
alpha

B.
beta

C.
gamma

D.
delta

Explanation:
shift shifts all arguments to the left (meaning arg1 becomes arg2, arg2 becomes arg3, …), so after the shift the 2nd argument becomes gamma.



Leave a Reply 1

Your email address will not be published. Required fields are marked *


Diego Perfeito

Diego Perfeito

The script/exercise is not funcional. The correct:
We have bash script ~/myscript shown below:
shift
echo $2
We call this script:
~/myscript alpha beta gamma delta

See,ok = C.gamma

The error is “echo $2” with parameter in shift.
shift only reduce one in left order.