0

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

MetalSnake
  • 277
  • 3
  • 14

2 Answers2

1

You can try this way

last_arg () {
shift $(($#-1))
echo "$@"
}
last=$(last_arg "$@")
echo "all but last = ${@%$last}"
ctac_
  • 2,413
  • 2
  • 7
  • 17
  • this had weird effects, with some param lists it would cut of the last 2 plus the last character of the param before that, and with others it did nothing. But it made me think of a working solution. – MetalSnake Jun 10 '18 at 08:44
  • @Diskutant give sample of param lists where it cut the last char and another where it do nothing. – ctac_ Jun 10 '18 at 09:14
0

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
MetalSnake
  • 277
  • 3
  • 14