How to get BASH to use * wildcard in command? - Ask Ubuntu
i've created bash script automate editing exif data in image files. can't figure out how script issue command * wildcard (asterisk) specify file name pattern.
the script assembles cli command executes if enter manually outside of bash script. within bash, script returns file not found error.
here's code:
#!/bin/bash # usage: place script in directory of jpg files exif data edited. echo press enter accept default values. # enter camera manufacturer. default="pentax" read -p "enter camera manufacturer [$default]: " cameramake cameramake=${cameramake:-$default} exifargs="-model=$cameramake" # enter camera model. default="k1000" read -p "enter camera model [$default]: " cameramodel cameramodel=${cameramodel:-$default} exifargs="$exifargs -make=$cameramodel" # enter slide film type. default="kodachrome slide film." read -p "enter slide film type [$default]: " filmtype filmtype=${filmtype:-$default} exifargs="$exifargs -imagedescription='pie ps-5000 slide scanner. vuescanner 32 scanning softare. $filmtype'" # enter file name pattern. default="*.jpg" read -p "enter file name pattern [$default]: " namepattern namepattern=${namepattern:-$default} exifargs="$exifargs $default" #use exiftool edit exif data echo /home/richard/dropbox/pictures/tools/exiftool/exiftool "$exifargs" /home/richard/dropbox/pictures/tools/exiftool/exiftool "$exifargs"
i inserted "echo" command check command correct. (at leats cli). results of running script is:
richard@richard-laptop:~/dropbox/pictures/photos/test$ sh exifbatch.sh press enter accept default values. enter camera manufacturer [pentax]: enter camera model [k1000]: enter slide film type [kodachrome slide film.]: enter file name pattern [*.jpg]: /home/richard/dropbox/pictures/tools/exiftool/exiftool -model=pentax -make=k1000 -imagedescription='pie ps-5000 slide scanner. vuescanner 32 scanning softare. kodachrome slide film.' *.jpg no file specified
but when enter exact same text create script on command line, functions want, finding files in current directory match name pattern. (the warnings thrown exiftool expected.):
richard@richard-laptop:~/dropbox/pictures/photos/test$ /home/richard/dropbox/pictures/tools/exiftool/exiftool -model=pentax -make=k1000 -imagedescription='pie ps-5000 slide scanner. vuescanner 32 scanning softare. kodachrome slide film.' *.jpg warning: [minor] ignored empty rdf:seq list darktable:mask_id - 1987_california-01.jpg warning: [minor] ignored empty rdf:seq list darktable:mask_id - 1987_california-02.jpg 2 image files updated
how change basch script command executed on cli? think there's wrong how i'm using * character. if don't put quotation marks (") around $exifargs variable name, bash interprets *.jpg , appends file names string, confounds exiftool command.
thanks!
quoting in shell tricky. if want use several parameters, when of them contain whitespace, use arrays. note need real bash
run script use arrays, don't start script sh
, runs dash
instead, no array support.
args=( -model="$cameramake" -make="$cameramodel" -imagedescription="pie ps-5000 slide scanner. vuescanner 32 scanning softare. $filmtype" $namepattern ) exiftool "${args[@]}"
btw, sure want name variable holding model "make" , naming variable holding maker "model"? note "software" has w after t.
Comments
Post a Comment