bash shell script not working as intended using cmp with output redirection -
i trying write bash script remove duplicate files folder, keeping 1 copy. script following:
#!/bin/sh f1 in `find ./ -name "*.txt"` if test -f $f1 f2 in `find ./ -name "*.txt"` if [ -f $f2 ] && [ "$f1" != "$f2" ] # if cmp $f1 $f2 &> /dev/null # not work if cmp $f1 $f2 rm $f2 echo "$f2 purged" fi fi done fi done
i want redirect output , stderr /dev/null
avoid printing them screen.. using commented statement script not work intended , removes files first..
i'll give more informations if needed.
thanks
&>
bash syntax, you'll need change shebang line (first line) #!/bin/bash (or appropriate path bash.
or if you're using bourne shell (/bin/sh
), have use old-style redirection, i.e.
cmp ... >/dev/null 2>&1
also, think &>
introduced in bash 4, if you're using bash, 3.x you'll still need old-style redirections.
ihth
Comments
Post a Comment