Questions tagged [zsh]

The Z shell (Zsh) is a Unix shell that can be used as an interactive login shell and as a powerful command interpreter for shell scripting.

zsh
Filter by
Sorted by
Tagged with
2 votes
4 answers
2k views

replace characters in Zsh variable

I am trying to replace all the - chars with _ chars in a specific variable. Tried to use the tr function. What am I missing? Thanks! user@mbp-user ~ % echo $APP_ID app1_someinfo_info-text_text-...
Stat.Enthus's user avatar
2 votes
2 answers
1k views

What does the percentage sign in zsh shell come from?

When I run this piece of code (from a tutorial to binary security), I always get an "%" in my zsh shell. Where do these percentage signs come from and how to get rid of them? #include <...
zell's user avatar
  • 9,990
2 votes
2 answers
5k views

Forward / backward words in the VSCode terminal

What commandID's govern moving forward or backward a word in the VSCode terminal? (say running Zsh) Background I know that these commands are bound Option + Right and Option + Left respectively since ...
Amelio Vazquez-Reina's user avatar
2 votes
2 answers
2k views

Formatting du command output

Is there a way to format(in a shell command chain) the following output of du -s -k * 287720 crm-cc 21500 crm-mvh 40360 elasticsearch-5.1.2 293292 electron-quick-start 44636 hexagon 193572 ...
Kuba Szymanowski's user avatar
2 votes
2 answers
2k views

Zsh returning `<function>:<linenumber> = not found`

I used the have the following tmux shortcut function defined in a separate script and aliased, which worked fine but was messy. I decided to move it to my .zshrc where it naturally belongs, and ...
Bennett Talpers's user avatar
2 votes
1 answer
4k views

Zsh Prompt Customization

Hi I know that you set the prompt variable to edit the prompt like this export PROMPT="This is the date %d" How do you execute a command and print the result everytime when prompt loads.
fancy_duck6's user avatar
2 votes
2 answers
2k views

zsh: raise error when variable not defined

One nasty aspect with zsh (or with shell scripting in general) is, that if you mistype a variable name, and the resulting name doesn't exist, it is silently treated as empty string, which makes bugs ...
user1934428's user avatar
  • 21.1k
2 votes
3 answers
21k views

How to edit file content using zsh terminal?

I created an empty directory on zsh and added a file called hello.rb by doing the following: echo 'Hello, world.' >hello.rb If I want to make changes in this file using the terminal what's the ...
Marvine Chi's user avatar
2 votes
2 answers
3k views

How can I use aria2 with pacman?

I want to make an alias for zsh to download packages by aria2 and install them by pacman, I don't want to use aria2c by adding xfercommand to pacman.conf because of 2 things: First my internet ...
GmArian's user avatar
  • 21
2 votes
2 answers
901 views

case insensitive glob listing in zsh

I have the following code: $ print -l backgrounds/**/*.((#i)jpg|jpeg|gif|webp|png|svg|xcf|cur|ppm|pcd) the intention was to list some image file indifernet of the case of file termination. But ...
user898297's user avatar
2 votes
5 answers
9k views

Why error "illegal character: ^M"?

I got some sort of formatting -problem that I cannot understand, a short example below using Zsh. Why? $ values=( 300 400 ) $ echo "scale=20; $values[1]-$values[2]" | bc (standard_in) 1: illegal ...
hhh's user avatar
  • 51.8k
2 votes
6 answers
8k views

Checking for rbenv shims in PATH: found at wrong position

I try to check my rbenv problem with using its rbenv-doctor command ; curl -fsSL https://github.com/rbenv/rbenv-installer/raw/main/bin/rbenv-doctor | bash I get this; Checking for `rbenv' in PATH: /...
Asyraf's user avatar
  • 627
2 votes
2 answers
2k views

git commit -m "add !empty check" zsh: event not found: empty

I just observed having ! before a git commit message triggers events in zsh. Not sure if it's zsh issue or git feature. Please explain.
Jagadesha NH's user avatar
  • 2,639
2 votes
3 answers
2k views

Bash export variables but only for current command

I want to load some environment variables from a file before running a node script, so that the script has access to them. However, I don't want the environment variables to be set in my shell after ...
Cully's user avatar
  • 6,746
2 votes
2 answers
581 views

In Bash, what is the meaning of every piece of "${BASH_SOURCE:-${(%):-%x}}"

Recently I wanted to know the best way to get the path to the currently running script/file in Bash. I found a lot of answers. In particular one was: "${BASH_SOURCE:-${(%):-%x}}" I remember ...
DavidT's user avatar
  • 727
2 votes
1 answer
1k views

ZSH - How can I join an array using the colon ":" character/escape colon character?

I don't know how to escape colons when using the zsh j:string: array expansion sequence. In my ~/.zshrc I find it pleasing to build up my PATH as an array. path_array=( /sbin /usr/sbin $HOME/...
merge failure's user avatar
2 votes
3 answers
376 views

Bash use something other than '~' to represent home directory? [closed]

Is it possible with bash (or maybe even zsh) to use a character other than the tilde ("~") do designate one's home directory? For example, "cd ~" takes you to your home directory. Hitting the shift ...
Jim's user avatar
  • 14k
2 votes
2 answers
2k views

shell function definition with and without keyword

It took me forever to find out that the reason the following piece of shell script doesn't work: if command -v z > /dev/null 2>&1; then unalias z 2> /dev/null z() { [ $# ...
Fuoco's user avatar
  • 31
2 votes
3 answers
3k views

Detaching a background process in zsh so that I can close the terminal

I have a terminal process running zsh in the Cygwin environment. I want to start a background process and then close the terminal process and have the background process running. However, when I exit ...
user1934428's user avatar
  • 21.1k
2 votes
2 answers
97 views

Get directory of an executable using which

I would like to use the which command to cd directly into a directory. cd $(which python3.6) Obviously this will not work, since which python3.6 will return an executable. Now the question is: ...
Johan Vergeer's user avatar
2 votes
2 answers
4k views

Git thinks a commit message is a command not found

I'm following along a Udacity course right now and after typing this: g cmp "adds string.replace() quiz" I got the error messages git:3: command not found: quiz git:80: command not found: quiz git:...
vaponteblizzard's user avatar
2 votes
2 answers
2k views

Weird behaviour with zsh PATH

I just encourage a weird problem with zsh today. My environment is Mac OS X Yosemite, zsh 5.0.5 (x86_64-apple-darwin14.0) In .zshrc, I have manually set the PATH variable to something like export ...
DQM's user avatar
  • 572
2 votes
1 answer
3k views

What does it mean if my (zsh) shell throws these errors/warnings at me every time I open the terminal?

This is what I see every time I launch my Terminal.app since I upgraded from Mavericks to Yosemite: dyld: Library not loaded: /usr/local/lib/libpcre.1.dylib Referenced from: /usr/local/bin/zsh ...
Wizek's user avatar
  • 4,944
2 votes
2 answers
16k views

zsh while loop exiting prematurely in a triple nested loop using floating point arithmetic

I have a zsh script that should generate a bunch of Z-matrix files, but it exits the while loops after one iteration. N and M never increase #!/bin/zsh n=0.5 m=0.5 a=60.0 i=1 while [[ $n -le 1.5 ]]...
user avatar
2 votes
3 answers
116 views

Process substitution with heredoc works in zsh. How to make it work in bash?

I want the ability to pass a heredoc to the source command for local interpretation. The body of the heredoc document will be injected later before calling the script, and can be multiline. I came up ...
Danilo Pianini's user avatar
2 votes
1 answer
2k views

Terminal error: Node.js environment variables are disabled

Starting today I receive the following error in my terminal (iTerm2, zsh shell, MacOS Sonoma) when I run some commands, for example when opening VSCode with the code . command: [0201/192142.001386:...
Guillermo Brachetta's user avatar
2 votes
2 answers
4k views

Find for YML and YAML files on bash find

I am trying to find all .yaml and .yml I tried find . -name '*.{yml,yaml}' -exec echo "{}" \; But no results Neither in the following way find . -name '*.yml' -name '*.yaml' -exec echo &...
Rodrigo's user avatar
  • 496
2 votes
2 answers
355 views

Make ZSH pass a variable as space-delimited parameters

I would like to create an alias that works in zsh and bash, but weirdly enough zsh tries to pass on an unquoted variable as a single argument: ❯ zsh -f grasshopper% LS_OPTIONS="-l -a" &&...
xeruf's user avatar
  • 2,852
2 votes
1 answer
3k views

zsh git autocomplete: __git_find_on_cmdline error

I am trying to get git autocomplete working with zsh and am running into a weird error (even though the autocomplete appears to complete successfully): Installation: mkdir -p ~/.zsh cd ~/.zsh curl -o ...
Raine Revere's user avatar
  • 32.3k
2 votes
3 answers
6k views

~/.zshrc alias with a space

I have a bad habit of putting spaces in my folder/file names. Today it bites me. I have a folder called NFB Lab in which I installed NFB Lab. I wanted to add the shortcut/command nfb and pynfb to the ~...
Mathieu's user avatar
  • 5,536
2 votes
1 answer
3k views

Using custom colors in zsh PS1 (prompt) env var causes problems with whitespace

My setup: zsh 5.7.1 (x86_64-apple-darwin19.0) macOS Catalina 10.15.5 Here's the standard PS1 var: PS1="%n@%m %~ %# " Problems arise when I try adding text coloring using either ANSI colors ...
rombez's user avatar
  • 2,137
2 votes
3 answers
1k views

How to keep/remove numbers in a variable in shell?

I have a variable such as: disk=/dev/sda1 I want to extract: only the non numeric part (i.e. /dev/sda) only the numeric part (i.e. 1) I'm gonna use it in a script where I need the disk and the ...
Ben's user avatar
  • 6,551
2 votes
1 answer
2k views

Mac OSx terminal : "not a valid identifier" on function definition

I have a bash script in which I define the below function, function start-if-exists() { if [ "`docker container ls -a|grep $1`" ]; then echo "Container $1 exists. Starting $1..." ...
Kannan Ramamoorthy's user avatar
2 votes
1 answer
8k views

"make dependencies" on Mac gives --> "make: lsb_release: Command not found" error

$ make dependencies in my terminal on Mac gives make: lsb_release: Command not found Here is the full message: make: lsb_release: Command not found Configured with: --prefix=/Applications/Xcode....
Jonathan's user avatar
  • 143
2 votes
2 answers
2k views

How can I "delay" in Zsh with a float-point number?

In Zsh there is a wait (for a process or job) command, a while (Seconds == Delay) command, and a sched (Do later if shell still running) command, but no "delay" command. If there were, I fear it ...
Micah W's user avatar
  • 378
2 votes
5 answers
314 views

How can I get xargs to do something with the input, then do another thing?

I'm in zsh. I'd like to do something like: find . -iname *.md | xargs cat && echo "---" > all_slides_with_separators_in_between.md Of course this cats all the slides, then appends a ...
Mark Bolusmjak's user avatar
2 votes
5 answers
16k views

terminate simple python server wont shut down with ctrl + C

I ran a simple web server using python -m simpleHTTPServer 8888 &. it starts well. Then used ctrl+C to attempt to terminate it, and I go to http://localhost:8888/ and the server is still ...
Lukasz's user avatar
  • 97
2 votes
3 answers
1k views

How can I forward bash/zsh arguments to another shell

I'm working on a system with a lot of tcsh configuration scripts, requiring me to run most programs through tcsh. I've attempted to make this easy for myself by adding this to my ~/.zshrc: # run ...
Eric's user avatar
  • 96.6k
2 votes
5 answers
97 views

Is there a way to reference other parts of the command being entered in bash, similar to history expansion

I often need to refer to a piece of text in a bash command for example: git mv _fav-locations-cluster.html.erb partials/_fav_locations_cluster.html.erb edit #1 Note that it's going from dashes -> ...
timpone's user avatar
  • 19.6k
2 votes
2 answers
677 views

zsh -- not seeming case sensitive?

I was trying to copy some files with the same name, but different case, to the same directory. See these steps: ~/tmp $ echo "First" > test ~/tmp $ echo "Second" > Test ~/tmp $ ls test ~/tmp $ ...
ashgromnies's user avatar
  • 3,295
2 votes
2 answers
2k views

zsh: unexpected output from awk printf

In bash I can do the following: $ printf "foo\nbar\n" | awk '{printf "%s\n", $1}' foo bar … but in zsh when I do the same, I get this: $ printf "foo\nbar\n" | awk '{printf "%s\n", $1}' [m\n", ...
dotcode's user avatar
  • 185
2 votes
2 answers
1k views

How to add colors with a pipe?

I want to pipe the output of a command to something able to color the occurrences of a specific word. Example: echo "ABC DEF GHI" | magic_color_thing("DEF") should print out ABC DEF GHI with DEF ...
Ale's user avatar
  • 19
2 votes
3 answers
526 views

Filter time(1) output to get time values only

how do I filter certain time command output values under OS X? I have tried ➜ ~ (time ls -la)| grep system|awk "{print $4, $6, $8, $10}" ls -G -la 0.01s user 0.01s system 16% cpu 0.102 total ...
Tadas T's user avatar
  • 2,569
2 votes
2 answers
1k views

Programming customized tab completion for zsh

Sorry if my google fu is too weak, but: I simply want to adjust zsh so that I can tab complete someappname -s using the contents (filenames) of ~/somedir For example: someapp -s f<tab> ...
Pistos's user avatar
  • 23.4k
2 votes
1 answer
2k views

Changing default shell from zsh to bash on MacOS (Catalina and beyond) [closed]

I felt comfortable using bash shell on MacOS. But Catalina replaced it with zsh. Why? Can I switch it back? If so, how? Does it make sense to do so? Any gotchas?
P i's user avatar
  • 29.9k
2 votes
2 answers
533 views

oh-my-zsh fast dry-run=client -o yaml for kubectl

I am using zsh with oh-my-zsh and I put an entry into my ~/.zshrc to have a shortcut for the option --dry-run=client -o yaml as a variable and be faster for generating yaml files with imperative ...
tba's user avatar
  • 149
2 votes
4 answers
128 views

How to find the line number with maximum context length with shell script?

I have a file with each line containing a string. I need to find the largest-N lines. I am able to find the lines with largest number of lines. For example, largest-1 could be found by: cat ./test.txt ...
Exploring's user avatar
  • 2,871
2 votes
2 answers
24k views

zsh: command not found on MacOS Monterey

I wanted to create a react project and when I executed the command it said zsh: command not found: npx Then I tried the ls command and it said zsh: command not found: ls. After setting the export PATH=...
Minsaf's user avatar
  • 242
2 votes
1 answer
4k views

Bash completion does not work in ZSH/Oh-My-ZSH because COMP_WORDS is not an array

I'm writing a bash command line tool for which I want to enable bash completion using completely. I have the following bash completion. After I eval "$(./cli completion)" (which outputs the ...
Nicolas's user avatar
  • 345
2 votes
1 answer
112 views

What part of this one-line script is specific to zsh?

I wrote a simple program called sarcasm that simply takes all its arguments, concatenates them, and converts the resulting string use 'aLtErNaTiNg CaPs'. I have written a simple one-line shell script ...
AJ-Williams1's user avatar

1
29 30
31
32 33
122