문제

I have written a command procedure that takes 12 positional arguments. How can i iterate only through the first 10 (for example). If i use shift [n], then argument $0 comes in but I don't want to use it. Can I use something like list comprehension?:

for arg in [$1..$10]
do 
   echo $arg
done
도움이 되었습니까?

해결책

Use parameter expansion like so:

for i in "${@:1:10}"; do
   echo "$i"
done

For more info, see man bash -> Parameter Expansion -> Substring Expansion

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top