linux - Bash - Executing a command in a script adding single quotes to a variable containing spaces -
i writing script executes necessary commands train tesseract language , want receive font argument (e.g.: dejavu sans bold) , execute command text2image --text=trainingfile.txt --outputbase=eng.dejavusansbold.exp0 --font='dejavu sans bold' --fonts_dir=/usr/share/fonts. notice --font='dejavu sans bold' has font name single quoted. since receive font argument, need add quotes , use name.
after different approaches, "most effective" attempt text2image --text="${trainingtextfilename}" --outputbase="${languagecode}"."${fontnamewithoutblanks}".exp0 --font="'""${fontname}""'" --fonts_dir=/usr/share/fonts still not working... ("languagecode" , "fontnamewithoutblanks" other variables).
after running script line, notification saying font not recognized although works when execute "manually" in console. using set -x , set +x line (of script) looks this: text2image --text=contenttraint.txt --outputbase=gdfdd.dejavusansbold.exp0 '--font='\''dejavu sans bold'\''' --fonts_dir=/usr/share/fonts. have no idea how go away quotation added because of spaces...
can me, please?
be clear command want execute. when type
text2image --text=trainingfile.txt --outputbase=eng.dejavusansbold.exp0 \ --font='dejavu sans bold' --fonts_dir=/usr/share/fonts to shell, happens shell invokes command text2image 4 arguments: --text=trainingfile.txt,
--outputbase=eng.dejavusansbold.exp0,
--font=dejavu sans bold, --fonts_dir=/usr/share/fonts.
the purpose of single quotes tell shell --font=dejavu sans bold 1 argument. in order answer question, though, need know how executing command (ie, need show code). if have font name in variable $font, do:
text2image --text=trainingfile.txt --outputbase=eng.dejavusansbold.exp0 \ --font="$font" --fonts_dir=/usr/share/fonts if font passed script argument, do:
font=$1 text2image ... --font="$1" ... if constructing command more dynamically, may need else.
Comments
Post a Comment