Skip to main content

All Questions

Tagged with
1 vote
1 answer
178 views

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 ...
Justin Breen's user avatar
7 votes
2 answers
1k views

Echoing "!" inside a string does some weird things [duplicate]

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 ...
Bog's user avatar
  • 1,034
2 votes
2 answers
133 views

Test fails (correctly) on command line, but succeeds (incorrectly) in script

For the sake of this question, assume that the glob /a/b/c/* produces no matches. This means that the following test should fail (in other words, it should produce a non-zero $?): [[ -n /a/b/c/*(#qN) ]...
kjo's user avatar
  • 15.6k
2 votes
2 answers
892 views

Escape variable for zsh's `print -P`

I was looking for a way to escape a variable containing format specifiers and special characters like quotes, backslashes and line breaks so that when passing it to print -P it'll print out literally. ...
BrainStone's user avatar
  • 3,724
1 vote
2 answers
341 views

Please explain the behavior of these parameter expansions using IFS?

I'm trying to figure out how to use the ${parameter%word} expansion with $@ and $*. It started by trying to make a script to combine pdfs using ghostscript, but I ran into some weird behavior with ...
mangoduck's user avatar
0 votes
1 answer
182 views

How to set sed command correctly

When I try following commands, (I'd like to rewrite sql). Day='2020/12/1' Dir=/home/test/data sql=`cat $Dir"/"$test".sql" | sed -e "s/Day/$Day/g"` I suffered following ...
Heisenberg's user avatar
2 votes
1 answer
1k views

Unable to run npm install with version specification

I am trying to run a simple npm install with zsh terminal. npm install --save-dev @typescript-eslint/eslint-plugin@^4.0.0 zsh: no matches found: @typescript-eslint/eslint-plugin@^4.0.0 It appears ...
StuartM's user avatar
  • 123
1 vote
1 answer
324 views

Using variables for Ghostscript options/flags causes errors

I am scripting the creation/manipulation of PDF files so I am using gs (Ghostscript). The problem I am having is that if I use a variable for the the options, gs errors out. The command that I am ...
Allan's user avatar
  • 1,050
3 votes
1 answer
2k views

What's the difference between test command and individual conditional expression surrounded by [[]]? [duplicate]

I am learning the zsh in the conditional expressions part, and I found some unreasonable output. For example: $ mkdir emptyspace && cd emptyspace $ var_assigned_with_emptystring="" $...
Anon's user avatar
  • 405
73 votes
1 answer
13k views

What is the difference between the "...", '...', $'...', and $"..." quotes in the shell?

Sometimes I see shell scripts use all of these different ways of quoting some text: "...", '...', $'...', and $"...". Why are there so many different kinds of quote being used? Do ...
Michael Homer's user avatar
2 votes
1 answer
81 views

Generating quoted command arguments

I'm working with a HTTP API that demands a very particular set of signed headers + JSON body. And I really want to cURL it for debugging and sanity in general. So, I've written a small script that, ...
Morten Siebuhr's user avatar
10 votes
1 answer
17k views

Using a variable as a case condition in zsh

My question is the zsh equivalent of the question asked here: How can I use a variable as a case condition? I would like to use a variable for the condition of a case statement in zsh. For example: ...
Smashgen's user avatar
  • 393
6 votes
3 answers
7k views

shell: Quote string with single quotes rather than backslashes

How can I quote a string with single quotes? Eg, I can do: $ printf "%q\n" 'two words' two\ words $ Is there a way to get a single- (or double-) quoted string as output, ie: $ MAGIC 'two words' '...
Tom Hale's user avatar
  • 31.2k
25 votes
5 answers
9k views

Why doesn't alias foo='echo "This is a quote: \'"' work? [duplicate]

In order to remind myself when I try to use shopt in Zsh instead of setopt, I created the following alias, testing it first at a shell prompt: $ alias shopt='echo "You\'re looking for setopt. This is ...
iconoclast's user avatar
  • 9,248
5 votes
1 answer
3k views

Command substitution not occurring for PS1 variable in zsh

I'm having the hardest time trying to get dynamically evaluated command output in my PS1 prompt with zsh on Ubuntu 17.10. Here are a few attempts I've made (I begin in directory /abc, and the prompt ...
Tony's user avatar
  • 269

15 30 50 per page