开发者

How do I find the last argument being passed INTO a script from $@?

开发者 https://www.devze.com 2023-03-14 16:15 出处:网络
#!/bin/bash /home/someDir/myServer $@ #arguments go as follow: ./se开发者_JS百科rver IP SERVICE PORT
#!/bin/bash 

/home/someDir/myServer $@

#arguments go as follow: ./se开发者_JS百科rver IP SERVICE PORT

port = $@ ?

echo "your port "$port

This IS NOT what I'm looking for: last_arg="${!#}"


I think ${@: -1:1} (the space is mandatory, otherwise it gets confused and thinks you're using defaulting) will do it; the slice syntax, unlike subscripts, allows negative numbers to index from the end of the array.

0

精彩评论

暂无评论...
验证码 换一张
取 消