From: moonhkt on
Hi All

How to using shift to get remains value ?

LOGGING ()
{
v1=$1
v2=$2
while [ $# -gt 2 ]
do
shift
done

echo `date '+%Y/%m/%d %H:%M:%S'` :$v1:$v2:

}

LOGGING moon "hk welcome" "Hello"

my result

2010/07/15 16:15:26 :moon:hk welcome:

Expect
2010/07/15 16:15:26 :moon:hk welcome:Hello.....
From: pk on
moonhkt wrote:

> Hi All
>
> How to using shift to get remains value ?
>
> LOGGING ()
> {
> v1=$1
> v2=$2
> while [ $# -gt 2 ]
> do
> shift
> done
>
> echo `date '+%Y/%m/%d %H:%M:%S'` :$v1:$v2:
>
> }
>
> LOGGING moon "hk welcome" "Hello"
>
> my result
>
> 2010/07/15 16:15:26 :moon:hk welcome:
>
> Expect
> 2010/07/15 16:15:26 :moon:hk welcome:Hello.....

Once you've shifted what you need to shift, use "$@" to get all the
remaining arguments. $# will tell you how many of them are there,

From: Janis Papanagnou on
On 15/07/10 10:17, moonhkt wrote:
> Hi All
>
> How to using shift to get remains value ?
>
> LOGGING ()
> {
> v1=$1
> v2=$2
> while [ $# -gt 2 ]
> do
> shift
> done
>
> echo `date '+%Y/%m/%d %H:%M:%S'` :$v1:$v2:
>
> }
>
> LOGGING moon "hk welcome" "Hello"
>
> my result
>
> 2010/07/15 16:15:26 :moon:hk welcome:
>
> Expect
> 2010/07/15 16:15:26 :moon:hk welcome:Hello.....

You provided no variable after the last colon, so you don't get
any value printed.

And instead of a while loop you can always provide an argument
to shift. For example

shift 3

or

shift $(( $# - 2 ))

or whatever you desire.

Then the remaining arguments are accessible through "$@".

Janis