sup all trying to add to my variable
its 0001 and i wanna make it 0002 ect.... im using freebsd "sh"
its 0001 and i wanna make it 0002 ect.... im using freebsd "sh"
> its 0001 and i wanna make it 0002 ect.... im using freebsd "sh"
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
>> 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))
--
Trying to be happy is like trying to build a machine for which the only
specification is that it should run noiselessly.
Not in OP's one. It's not POSIX.Quote:>>> its 0001 and i wanna make it 0002 ect.... im using freebsd "sh"
[...]
> In some shells you can write
> (( i++ ))
--
Stphane
>[...]
>> In some shells you can write
>> (( i++ ))
>Not in OP's one. It's not POSIX.
>>[...}
>>>>>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.
--
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
9. A simple question about left-margin variable in emacs
10. Easy question , Easy answer ?
13. A simple question deserving a simple answer