Directory with colon in PATH variable [duplicate] - linux

This question already has answers here:
How to escape colon (:) in $PATH on UNIX?
(4 answers)
If there is a colon (:) in the directory name, how could I add it to $PATH? [duplicate]
(1 answer)
Closed 2 years ago.
Linux allows : character in file (or directory) names. Can a directory containing : in its name be added to shell PATH variable without screwing up PATH?

According to POSIX specification:
The prefixes shall be separated by a colon ( ':' )
Then, if you add a directory with <colon> to PATH It'll interpreted like a different path and sure you'll get a error.
https://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap08.html#tag_08_03

Related

extract starting and ending with a special character [duplicate]

This question already has answers here:
Extracting directory name from an absolute path using sed or awk
(7 answers)
How to extract directory path from file path?
(9 answers)
Closed 2 months ago.
extract starting and ending with a special character
Content from the file:
/genomes/date/pa341/abc.txt
/genomes/date/ha76870/xyz/a1.pdf
Result should be
/genomes/date/pa341/
/genomes/date/ha76870/xyz/

Why the assignment of an array string (with brackets) to environment variable is not working [duplicate]

This question already has answers here:
I just assigned a variable, but echo $variable shows something else
(7 answers)
Closed 2 years ago.
Execute the following command in bash shell:
export sz1='"authorities" : ["uaa.resource"]'
Now, try echo $sz1
I expect to see the following output:
"authorities" : ["uaa.resource"]
But instead I get this:
"authorities" : c
The interesting thing is that I have dozens of servers where I can execute this type of variable assignment and it works except on this server. This server has exactly the same OS version, profile, bash version etc. What could be the reason for this behavior?
Always quote your variables. Use
echo "$sz1"
When you don't quote the variable, word splitting and wildcard expansion is done on the variable expansion. On ["uaa.resource"] is a wildcard that will match any of the following filenames:
"
u
a
.
r
e
s
o
u
c
On that one machine you have a file named c, so the wildcard matches and gets replaced with that filename.

expand unix variable inside sed command [duplicate]

This question already has answers here:
Replace a string in shell script using a variable
(12 answers)
sed substitution with Bash variables
(6 answers)
Closed 4 years ago.
I need to replace current value in configuration file with new value which is assigned to variable ,
like
file_name=abc.txt
needs to be replaced like
file_name=xyz.txt
where $file=xyz.txt
I tried
sed -i 's/file_name=.*/file_name=$file/g' conf_file.conf
however the variable is not getting expanded,
it comes like file_name=$file.
any pointers?
This should work,assuming that variable file has value:xyz.txt assigned to it:
sed "s/file_name=.*/file_name=${file}/g" file_name
Output:
file_name=xyz.txt

Passing variable and evaluating string [duplicate]

This question already has answers here:
Lookup shell variables by name, indirectly [duplicate]
(5 answers)
How to get a variable value if variable name is stored as string?
(10 answers)
Bash - variable variables [duplicate]
(4 answers)
Closed 4 years ago.
I have a set of directories listed inside a text file as
DIR_A= (name of directory 1)
DIR_B= (name of directory 2)
....
I have a second script to which I would like to pass an argument like sh Scriptname varname where varname could be A, B, ...
Scriptname sources the initial text file and I would like this script to accept the passed varname (using $1) to echo DIR_varname.
Any ideas? TIA

Redirecting bash output to a path stored in a variable [duplicate]

This question already has an answer here:
Bash - Concatenating Variable on to Path
(1 answer)
Closed 7 years ago.
I'm trying to redirect my output to a file which has its path stored in a variable but I cant get it to work.
LOG_TEST="~/AVDS/logs/${HOSTNAME}_testlog.log"
echo "foo" >> ~/AVDS/logs/${HOSTNAME}_testlog.log
echo "bar" >> $LOG_TEST
The "foo" line will work fine but the "bar" line returns the error:
./testarea.sh: line 9: ~/AVDS/logs/tvpc-office_testlog.log: No such file or directory
What am I doing wrong here?
Tilde expansion only happens when unquoted.
Get in the habit of using $HOME, not ~, in scripts.

Resources