quoting

ls output display a file named "N'*" as "N'''*"

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 names" states: “Files with single quotes are printed in a ridiculous way!” This issue was quickly fixed in version 8.26: $ …

Total answers: 1

bash cd issue with path containing spaces: "too many arguments"

bash cd issue with path containing spaces: "too many arguments" 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 : # creating a path with spaces in it $mkdir …

Total answers: 1

Replace string ${FOO} by ${'$'}{BAR} with sed

Replace string ${FOO} by ${'$'}{BAR} with sed I have this string occurring N times in a file: ${FOO} that I have to replace by this string: ${‘$’}{BAR} This is my current state: sed "s/\${FOO}/\${‘\$’}{BAR}/" file.txt but it raises "bad substitution". How could I properly achieve that with sed (version 4.8) ? Asked By: s.k || …

Total answers: 1

How to use a variable in a command inside of a bash file

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 ( $NF != 0 ) print $0 }’ I need to automotize this …

Total answers: 3

How can I create a file named "?$*'ChouMi'*$?"?

How can I create a file named "?$*'ChouMi'*$?"? I need to create a file with this exact name "?$*’ChouMi’*$?" so that ls would show it as: $ ls | cat -e "?$*’ChouMi’*$?"$ $ Asked By: prince royce || Source Put the name in single quotes. This makes the shell not process backslashes or things that …

Total answers: 1

Why does -n with unquoted variable containing empty string return true?

Why does -n with unquoted variable containing empty string return true? 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 $? 0 Here we see that -n with unquoted variable …

Total answers: 1

How can I edit matching files if the paths contain whitespace in bash?

How can I edit matching files if the paths contain whitespace in bash? I sometimes grep (or rg aka ripgrep or ag aka silversearcher) for things and then want to edit the matching files. For the editor part I use bash’s history. ~$ rg someThing ./path/to/some/file.txt 1:someThing in there. ~$ vim $(!! -l) This works …

Total answers: 1

how to write function with nested commands

how to write function with nested commands I’m trying to write a find and cd function like so: findcd () { cd "$(dirname "$(find ‘$1’ -type ‘$2’ -name ‘$3′)")" } to be called like so: find . f [FILE_NAME] But it’s seeing the dollar sign and expecting more arguments as oppose to executing what’s inside. …

Total answers: 1

Run `git commit -m` with single quotes in zsh

Run `git commit -m` with single quotes in zsh I sometimes use characters such as ! and $ in commit messages, they need to be manually escaped, but not if you use single quotes like this git commit -m ‘My $message here!’. I tried to write a function to make gc and all text following …

Total answers: 1

Echoing "!" inside a string does some weird things

Echoing "!" inside a string does some weird things If I type in this: echo "Hello, World!" I don’t know the name of it, but it prompts me for the next line. You know the PS2 thing. Or if you type echo and press Enter. Why? Well I know that ! is a Special Variable …

Total answers: 2

Using a variable in between ' 's

Using a variable in between ' 's I have a bash script with a line that was originally this convert ‘%d.jpg[1-300]’ combined.pdf Uses convert from Imagemagick to strap a load of sequentially numbered jpgs in to a PDF. I’ve written a basic script to accept user input for a changeable number of pages and tried …

Total answers: 1

Show quotes with echo inside bash -c

Show quotes with echo inside bash -c I am trying to echo I say "Hello, World!" with bash -c. This is (some of) what I have tried: $ bash -c "echo I say "Hello, World"’!’""" $ bash -c "echo I say "’"’"Hello, World"’!’""" $ bash -c "echo I say """Hello, World"""’!’ $ bash -c $’echo …

Total answers: 2

Problem with single quote in Bash

Problem with single quote in Bash I have a sh script for initializing dzen2, and I want to use Source Code Pro font to use there. Here’s the code… param="-p -dock -fn ‘Source Code Pro-10’" # the generated_output function is not important generated_output | dzen2 $param The problem is, the script doesn’t work! dzen2 doesn’t …

Total answers: 1

How do I quote square brackets in Ansible variable value for regexp parameter?

How do I quote square brackets in Ansible variable value for regexp parameter? I use the ansible.builtin.lineinfile module to modify a PHP-FPM pool configuration file. How should I quote the square brackets (annot.: or other special characters) in a value of a variable for the regexp parameter? Without quoting the square brackets are interpreted as …

Total answers: 1

rsync does not exclude specified directory starting with a hash character (#)

rsync does not exclude specified directory starting with a hash character (#) I am trying to exclude the #recycle directory with rsync: $ rsync -Hauv -h -P –exclude ‘#recycle/’ –exclude @eaDir/ –exclude ‘.DS_Store*’ –exclude desktop.ini user1@src_server:/volume2/Extension_1 /destination/dir/ receiving incremental file list Extension_1/#recycle/subDir1/subDir2/ Extension_1/#recycle/subDir1/subDir2/BigVideo.mov 39.23G 82% 36.40MB/s 0:03:44 ^C $ (I also tried quoting .DS_Store* and …

Total answers: 1

Getting jq error when using variable in command line

Getting jq error when using variable in command line I am using jq to get the tag_name index with the script: curl https://api.github.com/repos/checkstyle/checkstyle/releases -H "Authorization: token $GITHUB_TOKEN" -o /var/tmp/cs-releases.json TARGET_RELEASE_NUM=$1 TARGET_RELEASE_INDEX=$(cat /var/tmp/cs-releases.json | jq -r "[.[].tag_name] | to_entries | .[] | select(.value=="checkstyle-${TARGET_RELEASE_NUM}") | .key") echo TARGET_RELEASE_INDEX="$TARGET_RELEASE_INDEX" I get the expected result only when I use …

Total answers: 1