Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (3) </ 1 [2] 3 >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Need help with bash< Next Oldest | Next Newest >
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Oct. 27 2005,17:42 QUOTE

for i in [1-9].jpg; do mv $i 0$i; done

No sissy pipes need apply :p


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
clacker Offline





Group: Members
Posts: 570
Joined: June 2004
Posted: Oct. 27 2005,18:05 QUOTE

Very nice!  Small, simple, efficient, and it does what you want.

I'll try to spend less time playing with my pipes  :;):
Back to top
Profile PM 
NotTheMama Offline





Group: Members
Posts: 42
Joined: April 2005
Posted: Oct. 28 2005,06:31 QUOTE

mikshaw,

I thought you would write it as:
for i in [1-9].jpg; do mv {,0}$i; done

Like your tip in the post: Bash, Tips for commandline and shell scripts

But great syntax...... :)
Back to top
Profile PM 
clacker Offline





Group: Members
Posts: 570
Joined: June 2004
Posted: Oct. 28 2005,12:29 QUOTE

NotTheMama, thanks for that link.  I was looking for it before but couldn't find it.

So what's the best way to reverse the process?  Remove the leading zero?  I had a complicated mess until I looked at the link from NotTheMama and the Advanced Bash-Scripting Guide and tossed in some parameter substitution.  But I'd bet there's a simpler way:

for i in 0[1-9].jpg; do mv $i ${i#0}; done

I wish I knew all this before when I was renaming files by stripping away the first part (always the same) and it took forever using the rename button in emelfm.
Back to top
Profile PM 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Oct. 28 2005,15:11 QUOTE

NotTheMama: I would have if the filenames were longer, but "mv {,0}$i" doesn't save any bytes or keystrokes from "mv $i 0$i" when you're working with single-character filenames. It's actually one additional stroke, plus an extra shift, and it's more difficult to read =o)
I'm glad people appreciate my input....i certainly appreciate all the knowledge I get from others here.

Clacker:  I can never remember how the string substitution works.  I recently bugged RobertS to help me out, but i still have to refer to the ABS guide to figure out when to use # or ## or %, etc


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
11 replies since Oct. 27 2005,15:53 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (3) </ 1 [2] 3 >/
reply to topic new topic new poll
Quick Reply: Need help with bash

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code