Skip to content

Instantly share code, notes, and snippets.

@ksysctl
Created May 8, 2012 03:01
Show Gist options
  • Save ksysctl/2632232 to your computer and use it in GitHub Desktop.
Save ksysctl/2632232 to your computer and use it in GitHub Desktop.
Remove spaces, sample fuction usign bash shell
#!/bin/bash
# original string, with spaces
my_var=" Fuck You! . ";
echo $my_var;
# the function
function trim() {
local string=$@;
string=${string//[[:space:]]};
echo $string;
}
# passing one argument
my_var=$(trim $my_var);
# modified string, without spaces
echo $my_var;
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment