My first shell script ever
Just wrote my first shell script, though it seems sort of sloppy to me. I wanted to rename 40-50 .html files to .txt, so I read a shell-scripting tutorial, learned a few new Linux commands, and eventually wrote this:
Code:
for F in `ls -a1 *.html` So, can someone suggest a better way of doing this sort of script? |
I think this should work.
Code:
#!/bin/bash |
Hi there!!
In my experience, there's always at least a dozen ways to do the same thing in a shell script, so this is just what I'd do, but here goes... for from in `ls *.html` do to=`echo $from | sed -e "s/.html\$/.txt/"` mv $from $to done I find sed quite fiddly to work with, but VERY useful - tweaking the sed command and "echo"ing the mv command until I get it right is how I do it. Hope it helps...... |
Ah, basename is a very easy way to do it -- wish I'd known about it. :) Never heard of the sed command before, either; I'll have to look up how to use it.
|
3 usefull commands to learn... i'm still learning them
grep, sed, awk :D |
I use grep alot, but I've never used those other two.
|
you don't even need a shell script; just use the "rename" command :P
rename .html .txt * |
Wow, lol. Linux has too many obscure commands. :)
|
There is no such thing as "too many"...:)
|
All times are GMT -5. The time now is 02:12 PM. |