bash - Shell script to add extension on file -
need help on please scrip receive parameters directories, browse thoses directories add together right extension on each file found, or if directory add together .aaa extension files doesnt have extension, , have utilize comand file determine file type (files not have extyension) thanks
#!/bin/sh dir in "$@"; file in "$dir"/*; if [[ -d $file ]] ext=dir else file -i * | egrep 'avi|txt|jpeg|pst' fi if [file eq avi] ext=avi else if [file eq txt] ext=txt else if [file eq jpeg] ext=jpeg fi done done
you mean this:
for dir in "$@" file in "$dir"/* ftype=$(file -i "$file") unset ext case $ftype in *directory*) ext=aaa ;; *avi*) ext=avi ;; *text*) ext=txt ;; *jpeg*) ext=jpeg ;; *ps*) ext=ps ;; *) echo "file '$ftype' not recognised file $file" >&2 go on ;; esac echo "renaming '$file' '$file.$ext'" mv "$file" "$file.$ext" done done
note there no need egrep
, , file
reports on directories well, no need -d
test.
edit: egrep
in original posted question. added unset
bash
No comments:
Post a Comment