Possible duplicate:How to trim whitespace from a bash variable?
I searched and tried to make some decisions, but nothing works for me ...
I have a shell variable that causes problems due to start and end spaces. how can we get rid of all spaces in one line using shell script?
I can imagine two options:
variable=" gfgergj lkjgrg " echo $variable | sed 's,^ *,,; s, *$,,'
or more
nospaces=${variable## } # remove leading spaces nospaces=${variable%% } # remove trailing spaces
There are so many ways to achieve this, awk oneliner:
kent$ echo " foo - - - bar "|awk '{sub(/^ */,"",$0);sub(/ *$/,"",$0)}1' foo - - - bar
Source: https://habr.com/ru/post/922018/More articles:The default process flags are erlangColor gamut colors gnuplot - mapDifferent version of file in Mercurial repo - mercurialHow to start using a chainsaw for Log4j? - javaAjax presents various input values โโusing jquery UI next button click - javascriptC ++ 11 move constructor with side effects - c ++How to manage Copy, Paste, Select All, Define in iPhone UITextView application? - iosRspec & FactoryGirl - validationOptimized javascript code to find the 3 largest elements and its indices in an array? - javascriptContinuous numbers in an Objective-C array, such as range () in Python - pythonAll Articles