Shell Script to add extension on file and directory -
i need help write script receive arguments directories in current directory , browse directory.
if found, , it's , directory script adds next extension: .aaa
but if found file pdf, or zip or mp3, should add together next extension: .bbb
we suppose files not have extension yet
example:if found directory hello should remane hello.aaa , if find pdf file name myfile remanes myfile.pdf,
am not sure if should utilize case ... in or else:
#!/bin/sh dir in "$@"; file in "$dir"/*; if [[ -d $file ]] ext=dir else file * if ???????? ext=pdf; # not sure how set status if teh file found pdf add together extension pdf. else if ???????? ext=zip # same thing if teh file found zip else if ?????? ext=mp3 # samething if file found mp3 done done #!/bin/sh dir in "$@"; file in "$dir"/*; # protect against empty dirs - shell passes # literal asterisk along in case case $file in "$dir/*") go on ;; esac if [ -d "$file" ]; ext=aaa go on fi case $(file "$file") in "gzip compressed"*) ext=gzip ;; "whatever file(1) says pdfs") ext=pdf ;; "mp3"*) ext=mp3 ;; # et cetera esac done done
shell
No comments:
Post a Comment