Note that there are some explanatory texts on larger screens.

plurals
  1. POreplace newline character in bash variable?
    text
    copied!<p>I am trying to understand the "cdargs-bash.sh" script with cdargs packages. And I have a question about in the following function:</p> <pre><code>function _cdargs_get_dir () { local bookmark extrapath # if there is one exact match (possibly with extra path info after it), # then just use that match without calling cdargs if [ -e "$HOME/.cdargs" ]; then dir=`/bin/grep "^$1 " "$HOME/.cdargs"` if [ -z "$dir" ]; then bookmark="${1/\/*/}" if [ "$bookmark" != "$1" ]; then dir=`/bin/grep "^$bookmark " "$HOME/.cdargs"` extrapath=`echo "$1" | /bin/sed 's#^[^/]*/#/#'` fi fi [ -n "$dir" ] &amp;&amp; dir=`echo "$dir" | /bin/sed 's/^[^ ]* //'` fi if [ -z "$dir" -o "$dir" != "${dir/ /}" ]; then # okay, we need cdargs to resolve this one. # note: intentionally retain any extra path to add back to selection. dir= if cdargs --noresolve "${1/\/*/}"; then dir=`cat "$HOME/.cdargsresult"` /bin/rm -f "$HOME/.cdargsresult"; fi fi if [ -z "$dir" ]; then echo "Aborted: no directory selected" &gt;&amp;2 return 1 fi [ -n "$extrapath" ] &amp;&amp; dir="$dir$extrapath" if [ ! -d "$dir" ]; then echo "Failed: no such directory '$dir'" &gt;&amp;2 return 2 fi </code></pre> <p>}</p> <p>What's the purpose of the testing:</p> <pre><code>"$dir" != "${dir/ /}" </code></pre> <p>Here the testing span over two lines; does it want to remove the newline character in <code>$dir</code> or maybe for some other reason? I am just starting to learn bash scripting and I have Googled some time but couldn't find any usage like this.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload