All Questions
503
questions
2
votes
1
answer
2k
views
escaping filename results from grep
How do I escape the output of grep so that bash can read the file names correctly?
I have a text file that is the output of a find command. For each line, I want to make a symlink. For now, I'm just ...
4
votes
2
answers
1k
views
Is there a way to printf $@ verbatim?
I want to write a script that echoes to stdout its $@ verbatim, including any potential double-quotes, without a newline.
What I have tried:
> cat ./script1
#! /usr/bin/bash
printf "%s %s" $0 ...
0
votes
1
answer
57
views
value of $VAR already contains backtick and/or single quote inside. How to handle it? How to properly pass $VAR to program? [duplicate]
$ bash --version
GNU bash, versione 5.2.26(1)-release (x86_64-pc-linux-gnu)
I don't know how to deal with $VAR when its value inside contains single quote (') and/or backtick (`).
I'm in the need of ...
0
votes
2
answers
2k
views
Exclude the output from ssh and only log the error if found
typeset -f | sshpass -e ssh -o StrictHostKeyChecking=no user@${IPADDRESS} "
$(cat);
IFERROR=$(checkscript);
echo "$IFERROR"" > ${SSHTEMPFILE} 2>&1
This line...I can't exclude the "...
-1
votes
1
answer
42
views
I can't grep some inputrc string
bind -p |grep -E "\\e.\":" work
but
bind -p |grep -E "\\e\\C-.\":" don't work
I tried a lot of combination
5
votes
1
answer
450
views
ls output display a file named "N'*" as "N'\''*"
System:
Ubuntu 22.04.3 LTS
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
ls (GNU coreutils) 8.32
Situation:
$ touch "N'*"
$ ls
'N'\''*'
"GNU Coreutils - Quoting File ...
1
vote
1
answer
130
views
bash cd issue with path containing spaces: "too many arguments" [closed]
I created a path with spaces, and when I try to change directory I get "too many arguments" error message despite escaping the spaces or quoting the path :
Here are the tests I made :
# ...
-1
votes
3
answers
94
views
How to use a variable in a command inside of a bash file
I use this command directly on our redhat linux server 8.8 and it's working correctly and I get the result I want:
grep '01-FEB-2024' /u01/app/server1/listener_scan/trace/listener_scan.log | awk '{ if ...
275
votes
4
answers
53k
views
Security implications of forgetting to quote a variable in bash/POSIX shells
If you've been following unix.stackexchange.com for a while, you
should hopefully know by now that leaving a variable
unquoted in list context (as in echo $var) in Bourne/POSIX
shells (zsh being the ...
0
votes
0
answers
59
views
Why isn't passed quoted $@ a single argument? [duplicate]
Why isn't passed quoted $@ a single argument?
f2()
{
echo "f2: $1"
}
f1()
{
local x=("$@")
f2 "${x[@]}"
}
f1 x y
Invocation:
$ bash t537.sh
f2: ...
0
votes
0
answers
45
views
escape in double and single quotation [duplicate]
I am confusing why bash can escape "..." but can't escape '...'? Can some one give me a hint? Thanks
test@test:~$ echo "He said, \"Hello world\""
He said, "Hello ...
19
votes
1
answer
46k
views
What characters need to be escaped in files without quotes?
I have browser-based shell/terminal that executes bash commands and I'm escaping spaces but it turns out that parenthesis also need to be escaped. What other characters need to be escaped for file ...
1
vote
1
answer
100
views
Why does -n with unquoted variable containing empty string return true? [duplicate]
From man bash:
-n string
True if the length of string is non‐zero.
Examples:
# expected
$ var=""; [ -n "$var" ]; echo $?
1
# unexpected?
$ var=""; [ -n $var ]; echo ...
2
votes
1
answer
229
views
How to proberly deal with quotes in filenames when using variables/arrays including the filenames in bash? [duplicate]
I have been working on a bash script for a few days and got stuck with filenames including single and double quotes.
Give I want to iterate over the following files in a directory:
'file1.txt'
'file2....
197
votes
6
answers
299k
views
How can we run a command stored in a variable?
$ ls -l /tmp/test/my\ dir/
total 0
I was wondering why the following ways to run the above command fail or succeed?
$ abc='ls -l "/tmp/test/my dir"'
$ $abc
ls: cannot access '"/tmp/test/my': No ...