Search Results

Search: Posts Made By: kri321shna
4,953
Posted By MadeInGermany
Don't strip the leading zeroes off=${1:-30} ...
Don't strip the leading zeroes
off=${1:-30}
ls -r ANI_WFMASS_PIST*.gif |
while IFS='T.' read -r f num t
do
new=$(printf '%05d' "$((10#$num + off))")
echo mv "${f}T$num.$t" "${f}T$new.$t"...
4,953
Posted By Don Cragun
Good idea. It works just fine with ksh. But...
Good idea. It works just fine with ksh. But note that it fails with bash if there are any leading 0s since bash will interpret a numeric string starting with 0 as octal instead of decimal.

If...
4,953
Posted By Don Cragun
It isn't just 10 and 11 that have a problem. ...
It isn't just 10 and 11 that have a problem. Note that 12 through 16 are converted to 40 through 44 instead of 42 through 46, respectively.
4,953
Posted By MadeInGermany
Some shells interpret num as octal when there is...
Some shells interpret num as octal when there is a leading zero.
But obviously 10#num gives syntax error.
I have corrected my post to 10#$num.
Works in any Posix shell including ksh,bash,zsh.
4,953
Posted By Don Cragun
Although $((10#$num + $off)) does what we want...
Although $((10#$num + $off)) does what we want for this script in bash, ksh, and zsh, the recognition of 10# (and 8# and 16#) is not mentioned in the POSIX standards; so there is no guarantee that it...
4,953
Posted By Don Cragun
This can be done only using shell built-ins...
This can be done only using shell built-ins (except for the ls and mv commands). Note that it uses a reverse order ls to move the highest numbered files first in case moving a lowered numbered file...
Showing results 1 to 6 of 6

 
All times are GMT -4. The time now is 09:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy