简体   繁体   中英

ash: Remove last param

I'm in a busybox environment which only has sh and ash available.

Now I'm doing a script in which I need to pass all but the last param to ln.

So far it looks like this:

#!/bin/ash
TARGET="/some/path/"

for last; do true; done

ln $@ $TARGET$last

Obviously now I pass the last param twice, first unmodified then modified with $TARGET in front of it.

How can I get rid of the last param in $@?

You can try this way

last_arg () {
shift $(($#-1))
echo "$@"
}
last=$(last_arg "$@")
echo "all but last = ${@%$last}"

Got a working solution now, it's not that nice, and it shifts the params, but until a better solution comes up this will do it.

for last; do true; done
while [[ "$1" != "$last" ]] ; do
    args="$args $1"
    shift
done

echo $args

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM