|
From: | John Kearney |
Subject: | Re: [Help-bash] inconsistency in expansions |
Date: | Mon, 07 May 2012 14:54:14 +0200 |
User-agent: | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 |
Am 07.05.2012 14:29, schrieb Greg Wooledge:
I don't know why he wants to do it but its not that difficult to decipher.On Sun, May 06, 2012 at 01:24:09PM -0600, Bill Gradwohl wrote:set -- "The cat " "ate the " "canary" echo $# x=$# declare string string="${*%${$#}}"What the bloody hell is that supposed to DO?I expected all of them to work.What is "work"? Seriously, tell us what you THINK it is supposed to do. Better yet, simply tell us what you WANT to do, and do not write any code, and we will tell you how to do it. Or we will tell you that it is not possible. Are you trying to print the Nth positional parameter, where N is an integer stored in some other variable? Then do this: set -- "the cat " "ate the " "canary" n=3 echo "${!n}" Or use an actual array: array=("$@") n=3 echo "${array[n]}" he wants to remove the text of the last argument from the end of every argument and print the resulting array separated by the first character to IFS. so using a normal arraysomething like this. declare -a tarray=(--test1 --test2 --test3 --test4 --test5 --) echo ${tarray[*]#${tarray[-1]}} "test1 test2 test3 test4 test5" |
[Prev in Thread] | Current Thread | [Next in Thread] |