0

I have the following script ,how do I remove the leading and trailing spaces for variable TAG ?

TAG=`find projectversions -build Current${BUILD} ${PROJECT}|grep ${PROJECT}`

echo "TAG  $TAG"
Jeremyapple
  • 253
  • 2
  • 6
  • 20
  • 1
    Which shell, specifically? The easiest way to do this in bash is with an extglob (`shopt -s extglob` at the top of your script, then `var=${var%%+([[:space:]])}`), but that's not available with `/bin/sh`. – Charles Duffy Jun 13 '18 at 20:38
  • #@CharlesDuffy - its `-bash` – Jeremyapple Jun 13 '18 at 20:41
  • In the future, use the bash tag in your questions, not the more generic shell tag, when an answer is intended to be used with bash. – Charles Duffy Jun 13 '18 at 20:41
  • (btw, you might consider making a habit of running your code through http://shellcheck.net/ and fixing what it finds). – Charles Duffy Jun 13 '18 at 20:42
  • okay, how do I fix this in `bash` – Jeremyapple Jun 13 '18 at 20:42
  • See the link up at the top of the question (below the header "This question already has an answer here:"). If you have trouble applying those answers, [edit] to show how you tried to apply them, and how you determined the result to have failed, ideally with a [mcve] letting someone else reproduce the problem themselves -- that will result in a more specific and answerable question. – Charles Duffy Jun 13 '18 at 20:43

0 Answers0