-2

I run a command:

script.sh ___bubu__

The content of the script.sh is:

echo $1

When executed I get

___bubu__

How can I remove the trailing spaces from command line passed arguments? I copy some params from a file and when pasting into command line I get some spaces and I do not want to manually remove the space. I am planning to use $1 as a parameter in a script. For example I want to create a folder with $1

redcom
  • 55
  • 3
  • 3
    When you say trailing spaces, do you actually mean leading underscores ? – 123 Jun 09 '15 at 10:50
  • Those quotes shouldn't be present in the output. Can you please [edit] your question to make it clearer what you're asking? – Tom Fenech Jun 09 '15 at 11:00
  • Trailing spaces would be removed if you echo without putting quotes around `$1`. – cdarke Jun 09 '15 at 11:12
  • Question for removing space is duplicated for: http://stackoverflow.com/questions/369758/how-to-trim-whitespace-from-bash-variable – Anton Krosnev Jun 09 '15 at 12:11

1 Answers1

0

Would something like this work?

..> more strip.sh 
#!/bin/bash

arg=$1
arg=${arg// /}
echo "unstripped: --$1--"
echo "stripped: --$arg--"

.03:163> ./strip.sh "  test "
unstripped: --  test --
stripped: --test--
Zoro_77
  • 397
  • 1
  • 4
  • 16