how to ++ my variable? simple question easy awnser

how to ++ my variable? simple question easy awnser

Post by Telio » Thu, 21 Aug 2003 18:34:55



sup all trying to add to my variable

its 0001 and i wanna make it 0002 ect.... im using freebsd "sh"

 
 
 

how to ++ my variable? simple question easy awnser

Post by Stephane CHAZELA » Thu, 21 Aug 2003 19:37:11



> sup all trying to add to my variable

> its 0001 and i wanna make it 0002 ect.... im using freebsd "sh"

You'd better store 1 in the variable, and only add leading zeros
when you display it.

i=1
i=$(($i + 1))
printf '%.4d\n' "$i"

If you use numbers with leading zeros, they will
be considered as octal numbers in POSIX shells.

If you have
i=0007 and want i=0008, you can do

i=$(awk -v i="$i" 'BEGIN{printf("%.4d", i+1)}')

Chances are that your whole script would be more easily
written in awk or perl, anyway.

--
Stphane

 
 
 

how to ++ my variable? simple question easy awnser

Post by Bill Marcu » Fri, 22 Aug 2003 12:06:26


On 20 Aug 2003 10:37:11 GMT, Stephane CHAZELAS



>> sup all trying to add to my variable

>> its 0001 and i wanna make it 0002 ect.... im using freebsd "sh"

> You'd better store 1 in the variable, and only add leading zeros
> when you display it.

> i=1
> i=$(($i + 1))

In some shells you can write
(( i++ ))

--
Trying to be happy is like trying to build a machine for which the only
specification is that it should run noiselessly.

 
 
 

how to ++ my variable? simple question easy awnser

Post by Stephane CHAZELA » Fri, 22 Aug 2003 17:31:28


[...}

Quote:>>> its 0001 and i wanna make it 0002 ect.... im using freebsd "sh"

[...]
> In some shells you can write
> (( i++ ))

Not in OP's one. It's not POSIX.

--
Stphane

 
 
 

how to ++ my variable? simple question easy awnser

Post by Michael Wa » Sat, 23 Aug 2003 09:45:05





>[...}
>>>> its 0001 and i wanna make it 0002 ect.... im using freebsd "sh"

>[...]
>> In some shells you can write
>> (( i++ ))

>Not in OP's one. It's not POSIX.

I would think it will be in future version of POSIX.
--

 
 
 

how to ++ my variable? simple question easy awnser

Post by Kevin Rodger » Sun, 24 Aug 2003 01:09:17






>>[...}

>>>>>its 0001 and i wanna make it 0002 ect.... im using freebsd "sh"

>>[...]

>>>In some shells you can write
>>>(( i++ ))

>>Not in OP's one. It's not POSIX.

> I would think it will be in future version of POSIX.

What leads you to believe that?  How does it help the OP?

--
Kevin Rodgers

 
 
 

1. easy question : how to set an environment variable ?

how do i set a env variable.

when i log in to unix, i always have to type
" cd /var/apache/www/htdocs/nglim "

i want to set a variable to this value and then

i can type cd wwwpath to go to this path.

how can i do that ?

thanks a lot.

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

2. How can I clean my First Boot record?????

3. easy question - bootx variables

4. ELF and a.out libraries at the same time?

5. simple shell script variable question

6. perf meter

7. variable expansion: simple question

8. CLNP and Linux?

9. A simple question about left-margin variable in emacs

10. Easy question , Easy answer ?

11. easy easy question

12. easy easy easy one

13. A simple question deserving a simple answer