When you use bash to move sample.sh below, an error is generated with a special variable that substitutes the variable.
Probably because it is treated as a string, I don't think I can pull the arguments. Is there any way to do this?
[root@test]#cat sample.sh
#!/bin/bash
echo$2
echo${2}
N = 2
echo${$N}
[root@test] #sh sample.sh abc
B
B
sample.sh: line 8: ${$N}: incorrect substitution
#!/bin/bash
echo$2
echo${2}
N = 2
echo${!N}
so that
% ./sample.sh foo bar
bar
bar
bar
can be achieved.
© 2025 OneMinuteCode. All rights reserved.