MetalSnake
MetalSnake

Reputation: 315

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 $@?

Upvotes: 0

Views: 85

Answers (2)

MetalSnake
MetalSnake

Reputation: 315

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

Upvotes: 0

ctac_
ctac_

Reputation: 2491

You can try this way

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

Upvotes: 1

Related Questions