![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Awk:Find length of string omitting quotes | jayakumarrt | Shell Programming and Scripting | 2 | 05-09-2008 12:48 AM |
| omitting lines from file A that are in file B | gneen | Shell Programming and Scripting | 14 | 02-20-2008 02:33 AM |
| spaces in filenames, for do | naviztirf | Shell Programming and Scripting | 4 | 10-17-2007 02:08 PM |
| tar contains duplicate filenames | dangral | UNIX for Dummies Questions & Answers | 2 | 03-14-2007 01:18 PM |
| code that reads commands from the standard i/p and executes the commands | Phrozen Smoke | High Level Programming | 4 | 01-21-2007 11:06 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
hello all,
this topic might have been discussed but I couldn't find it with searching. I am trying to do a for command that will dos2unix files one by one and save it under directory called backup (backup is in the same directory with other files). When I do: Code:
for i in * do dos2unix $i backup/"$i" done Code:
for i in * but not backup do cp files under backup done I hope I made sense... |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
You can try looking up the test command
you can use the if statement which also supports NOT,AND and OR. Check you shell manuals for syntax e.g. man sh, man ksh, man csh Here are some things you can check for with test -r filename True if filename exists and is readable. -w filename True if filename exists and is writable. -x filename True if filename exists and is executable. -f filename True if filename exists and is a regular file. -d filename True if filename exists and is a directory. -h filename True if filename exists and is a symbolic link. With all other primitives (except -L filename), the symbolic links are followed by default. -s filename True if filename exists and has a size greater than zero. -z s1 True if the length of string s1 is zero. |
|
#3
|
||||
|
||||
|
Code:
for i in !(dos2unix) do dos2unix $i backup/"$i" done |
|
#4
|
||||
|
||||
|
Quote:
Code:
$ for i in !(backup); do dos2unix $i backup/"$i" ; done bash: !: event not found |
|
#5
|
||||
|
||||
|
Bummer. Then I'd say to go with a test:
Code:
for i in *
do
if [[ $i != dos2unix ]]; then
dos2unix $i backup/"$i"
fi
done
|
|
#6
|
|||
|
|||
|
Code:
#!/bin/ksh # for i in * do if [ ! -d $i ] then dos2unix $i backup/"$i" fi done |
|||
| Google The UNIX and Linux Forums |