Skip to main content
Bumped by Community user
Bumped by Community user
added 4 characters in body
Source Link
ilkkachu
  • 147.8k
  • 16
  • 268
  • 441

I have hundreds of sub-directories which contain a dollar sign (i.e., "$"$) as the 1st character in their names, each of which needs to be visited. These sub-directories can not be renamed. The bash script function tries to visit each and (so far) to echo the path its in. Trying to do this via a built path string then eval it.

The line that print "cmd=${cmd}"cmd=${cmd} indeed shows "cmd=cd /rbyoko/c/$Ono.RCB"cmd=cd /rbyoko/c/$Ono.RCB as expected - however, the eval command mis-interprets the $Ono.RCB$Ono.RCB (probably as $Ono$Ono being empty var) and results in: "-bash: cd: /rbyoko/c/.BIN/: No such file or directory"-bash: cd: /rbyoko/c/.BIN/: No such file or directory then the following line prints "We are in /home/user"We are in /home/user (where the script was run from).

My question: how do I eval the string (and/or escape the sub-directory with "$"$) to actually succeed in visiting the desired sub-directory?

Here is my function:

visit_tree_recbin()
{
            strings="cdhlotpw"
            MACHINE=`uname -a`
            PWD=`pwd`
            for i in $(seq 1 ${#strings})
            do
                c="${strings:i-1:1}"
                echo "Letter $i: $c"
                #build eval string to do: cd "/rbyoko/${c}/\$Ono.RCB/"
                x1="cd /rbyoko/${c}/"
                x2="\$"
                x3="Ono.RCB/"
                cmd="${x1}${x2}${x3}"
                echo "cmd=${cmd}"
                eval "${x1}${x2}${x3}"
                echo "We are in " `pwd`
            done
}

I have hundreds of sub-directories which contain a dollar sign (i.e., "$") as the 1st character in their names, each of which needs to be visited. These sub-directories can not be renamed. The bash script function tries to visit each and (so far) to echo the path its in. Trying to do this via a built path string then eval it.

The line that print "cmd=${cmd}" indeed shows "cmd=cd /rbyoko/c/$Ono.RCB" as expected - however, the eval command mis-interprets the $Ono.RCB (probably as $Ono being empty var) and results in: "-bash: cd: /rbyoko/c/.BIN/: No such file or directory" then the following line prints "We are in /home/user" (where the script was run from).

My question: how do I eval the string (and/or escape the sub-directory with "$") to actually succeed in visiting the desired sub-directory?

Here is my function:

visit_tree_recbin()
{
            strings="cdhlotpw"
            MACHINE=`uname -a`
            PWD=`pwd`
            for i in $(seq 1 ${#strings})
            do
                c="${strings:i-1:1}"
                echo "Letter $i: $c"
                #build eval string to do: cd "/rbyoko/${c}/\$Ono.RCB/"
                x1="cd /rbyoko/${c}/"
                x2="\$"
                x3="Ono.RCB/"
                cmd="${x1}${x2}${x3}"
                echo "cmd=${cmd}"
                eval "${x1}${x2}${x3}"
                echo "We are in " `pwd`
            done
}

I have hundreds of sub-directories which contain a dollar sign (i.e., $) as the 1st character in their names, each of which needs to be visited. These sub-directories can not be renamed. The bash script function tries to visit each and (so far) to echo the path its in. Trying to do this via a built path string then eval it.

The line that print cmd=${cmd} indeed shows cmd=cd /rbyoko/c/$Ono.RCB as expected - however, the eval command mis-interprets the $Ono.RCB (probably as $Ono being empty var) and results in: -bash: cd: /rbyoko/c/.BIN/: No such file or directory then the following line prints We are in /home/user (where the script was run from).

My question: how do I eval the string (and/or escape the sub-directory with $) to actually succeed in visiting the desired sub-directory?

Here is my function:

visit_tree_recbin()
{
            strings="cdhlotpw"
            MACHINE=`uname -a`
            PWD=`pwd`
            for i in $(seq 1 ${#strings})
            do
                c="${strings:i-1:1}"
                echo "Letter $i: $c"
                #build eval string to do: cd "/rbyoko/${c}/\$Ono.RCB/"
                x1="cd /rbyoko/${c}/"
                x2="\$"
                x3="Ono.RCB/"
                cmd="${x1}${x2}${x3}"
                echo "cmd=${cmd}"
                eval "${x1}${x2}${x3}"
                echo "We are in " `pwd`
            done
}
Fixed formatting; improved punctuation; added tag.
Source Link

I have hundreds of sub-directories which contain a dollar sign (i.e., "$") as the 1st character in their names, each of which needs to be visited. These sub-directories can not be renamed. The bash script function tries to visit each and (so far) to echo the path its in. Trying to do this via a built path string then eval it.

theThe line that print "cmd=${cmd}" indeed shows "cmd=cd /rbyoko/c/$Ono.RCB" as expected - however, the eval command mis-interprets the $Ono.RCB (probably as $Ono being empty var) and results in: "-bash: cd: /rbyoko/c/.BIN/: No such file or directory" then the following line prints "We are in /home/user" (where the script was run from).

myMy question: how do I eval the string (and/or escape the sub-directory with "$") to actually succeed in visiting the desired sub-directory  ?

Here is my function:

visit_tree_recbin() { strings="cdhlotpw" MACHINE=uname -a PWD=pwd for i in $(seq 1 ${#strings}) do c="${strings:i-1:1}" echo "Letter $i: $c" #build eval string to do: cd "/rbyoko/${c}/$Ono.RCB/" x1="cd /rbyoko/${c}/" x2="$" x3="Ono.RCB/" cmd="${x1}${x2}${x3}" echo "cmd=${cmd}" eval "${x1}${x2}${x3}" echo "We are in " pwd
done }

visit_tree_recbin()
{
            strings="cdhlotpw"
            MACHINE=`uname -a`
            PWD=`pwd`
            for i in $(seq 1 ${#strings})
            do
                c="${strings:i-1:1}"
                echo "Letter $i: $c"
                #build eval string to do: cd "/rbyoko/${c}/\$Ono.RCB/"
                x1="cd /rbyoko/${c}/"
                x2="\$"
                x3="Ono.RCB/"
                cmd="${x1}${x2}${x3}"
                echo "cmd=${cmd}"
                eval "${x1}${x2}${x3}"
                echo "We are in " `pwd`
            done
}

I have hundreds of sub-directories which contain a dollar sign (i.e. "$") as the 1st character in their names, each of which needs to be visited. These sub-directories can not be renamed. The bash script function tries to visit each and (so far) to echo the path its in. Trying to do this via a built path string then eval it

the line that print "cmd=${cmd}" indeed shows "cmd=cd /rbyoko/c/$Ono.RCB" as expected - however, the eval command mis-interprets the $Ono.RCB (probably as $Ono being empty var) and results in: "-bash: cd: /rbyoko/c/.BIN/: No such file or directory" then the following line prints "We are in /home/user" (where the script was run from)

my question: how do I eval the string (and/or escape the sub-directory with "$") to actually succeed in visiting the desired sub-directory  ?

Here is my function:

visit_tree_recbin() { strings="cdhlotpw" MACHINE=uname -a PWD=pwd for i in $(seq 1 ${#strings}) do c="${strings:i-1:1}" echo "Letter $i: $c" #build eval string to do: cd "/rbyoko/${c}/$Ono.RCB/" x1="cd /rbyoko/${c}/" x2="$" x3="Ono.RCB/" cmd="${x1}${x2}${x3}" echo "cmd=${cmd}" eval "${x1}${x2}${x3}" echo "We are in " pwd
done }

I have hundreds of sub-directories which contain a dollar sign (i.e., "$") as the 1st character in their names, each of which needs to be visited. These sub-directories can not be renamed. The bash script function tries to visit each and (so far) to echo the path its in. Trying to do this via a built path string then eval it.

The line that print "cmd=${cmd}" indeed shows "cmd=cd /rbyoko/c/$Ono.RCB" as expected - however, the eval command mis-interprets the $Ono.RCB (probably as $Ono being empty var) and results in: "-bash: cd: /rbyoko/c/.BIN/: No such file or directory" then the following line prints "We are in /home/user" (where the script was run from).

My question: how do I eval the string (and/or escape the sub-directory with "$") to actually succeed in visiting the desired sub-directory?

Here is my function:

visit_tree_recbin()
{
            strings="cdhlotpw"
            MACHINE=`uname -a`
            PWD=`pwd`
            for i in $(seq 1 ${#strings})
            do
                c="${strings:i-1:1}"
                echo "Letter $i: $c"
                #build eval string to do: cd "/rbyoko/${c}/\$Ono.RCB/"
                x1="cd /rbyoko/${c}/"
                x2="\$"
                x3="Ono.RCB/"
                cmd="${x1}${x2}${x3}"
                echo "cmd=${cmd}"
                eval "${x1}${x2}${x3}"
                echo "We are in " `pwd`
            done
}
Are you sure the problem isn't just the assignment `x2="\$"`? Try `x2="\\$"` or `x2="\$
Source Link
steeldriver
  • 83.8k
  • 12
  • 124
  • 175

I have hundreds of sub-directories which contain a dollar sign (i.e. "$") as the 1st character in their names, each of which needs to be visited. These sub-directories can not be renamed. The bash script function tries to visit each and (so far) to echo the path its in. Trying to do this via a built path string then eval it

the line that print "cmd=${cmd}" indeed shows "cmd=cd /rbyoko/c/$Ono.RCB" as expected - however, the eval command mis-interprets the $Ono.RCB (probably as $Ono being empty var) and results in: "-bash: cd: /rbyoko/c/.BIN/: No such file or directory" then the following line prints "We are in /home/user" (where the script was run from)

my question: how do I eval the string (and/or escape the sub-directory with "$") to actually succeed in visiting the desired sub-directory ?

Here is my function:

visit_tree_recbin() { strings="cdhlotpw" MACHINE=uname -a PWD=pwd for i in $(seq 1 ${#strings}) do c="${strings:i-1:1}" echo "Letter $i: $c" #build eval string to do: cd "/rbyoko/${c}/$Ono.RCB/" x1="cd /rbyoko/${c}/" x2="$" x3="Ono.RCB/" cmd="${x1}${x2}${x3}" echo "cmd=${cmd}" eval "${x1}${x2}${x3}" echo "We are in " pwd
done }

I have hundreds of sub-directories which contain a dollar sign (i.e. "$") as the 1st character in their names, each of which needs to be visited. These sub-directories can not be renamed. The bash script function tries to visit each and (so far) to echo the path its in. Trying to do this via a built path string then eval it

the line that print "cmd=${cmd}" indeed shows "cmd=cd /rbyoko/c/$Ono.RCB" as expected - however, the eval command mis-interprets the $Ono.RCB (probably as $Ono being empty var) and results in: "-bash: cd: /rbyoko/c/.BIN/: No such file or directory" then the following line prints "We are in /home/user" (where the script was run from)

my question: how do I eval the string (and/or escape the sub-directory with "$") to actually succeed in visiting the desired sub-directory ?

Here is my function:

visit_tree_recbin() { strings="cdhlotpw" MACHINE=uname -a PWD=pwd for i in $(seq 1 ${#strings}) do c="${strings:i-1:1}" echo "Letter $i: $c" #build eval string to do: cd "/rbyoko/${c}/$Ono.RCB/" x1="cd /rbyoko/${c}/" x2="$" x3="Ono.RCB/" cmd="${x1}${x2}${x3}" echo "cmd=${cmd}" eval "${x1}${x2}${x3}" echo "We are in " pwd
done }

I have hundreds of sub-directories which contain a dollar sign (i.e. "$") as the 1st character in their names, each of which needs to be visited. These sub-directories can not be renamed. The bash script function tries to visit each and (so far) to echo the path its in. Trying to do this via a built path string then eval it

the line that print "cmd=${cmd}" indeed shows "cmd=cd /rbyoko/c/$Ono.RCB" as expected - however, the eval command mis-interprets the $Ono.RCB (probably as $Ono being empty var) and results in: "-bash: cd: /rbyoko/c/.BIN/: No such file or directory" then the following line prints "We are in /home/user" (where the script was run from)

my question: how do I eval the string (and/or escape the sub-directory with "$") to actually succeed in visiting the desired sub-directory ?

Here is my function:

visit_tree_recbin() { strings="cdhlotpw" MACHINE=uname -a PWD=pwd for i in $(seq 1 ${#strings}) do c="${strings:i-1:1}" echo "Letter $i: $c" #build eval string to do: cd "/rbyoko/${c}/$Ono.RCB/" x1="cd /rbyoko/${c}/" x2="$" x3="Ono.RCB/" cmd="${x1}${x2}${x3}" echo "cmd=${cmd}" eval "${x1}${x2}${x3}" echo "We are in " pwd
done }

Source Link
Loading