2022 Developer Survey is open! Take survey.

New answers tagged

1 vote

How to get unix time of 11PM, and 11PM CST tonight using BSD's date command?

Since you're tagging with zsh, note that zsh has builtin time parsing and formatting with its strftime builtin in the zsh/datetime module which is a raw interface to the standard strftime() (+ ...
user avatar
3 votes

How to get unix time of 11PM, and 11PM CST tonight using BSD's date command?

You should be able to specify :%M:%S as part of the format string and specify :00:00 as the time % /bin/date -j -f '%H:%M:%S%p %Z' '11:00:00PM GMT' Wed May 25 19:00:00 EDT 2022 The manpage for ...
user avatar
1 vote
Accepted

zsh function with fzf selection requires Enter

fzf-change-dirstack () { local dir print -rNC1 -- $dirstack | fzf --read0 --print0 | IFS= read -rd '' dir && cd -- $dir && zle -I } zle -N fzf-change-dirstack ...
user avatar
0 votes

ZSh script to batch process filenames containing spaces and substitute extension

To use Zsh modifiers (and other zsh specific syntax) a script added to a file should start by defining it is a zsh script #!/usr/bin/zsh Optionally, check the location of zsh first by using the which ...
user avatar
  • 101
1 vote

ZSh script to batch process filenames containing spaces and substitute extension

While your problem was that you had the script interpreted by sh instead of zsh, in zsh, you could use zmv here: #! /bin/zsh - autoload zmv zmv -P ffmpeg -o -i './(*).wma' './$1.wav' zmv normally ...
user avatar
0 votes

repair arch linux console

Since usermod needs root privileges, and you didn't add sudo to it in your question, I guess you still have root access to your computer. So, use that to install zsh or to change the shell to bash ...
user avatar
3 votes
Accepted

Run cargo command in subdirectories with user-specified arguments

The shell doesn't mess up with --. Just do: #! /bin/zsh - for toml (**/Cargo.toml(N.)) cargo -v "$@" --manifest-path $toml And call it as: that-script test -- --ignored Using zsh globbing ...
user avatar
0 votes

what is the zsh equivalent of bash's export -f

Everywhere I've read about this suggests that automatically importing functions is a bad idea, so I decided to just extract my scripts into a separate file that can be easily sourced in a subshell. I ...
user avatar
2 votes

How to automate the process to open 3 shells and run 3 commands?

Not an answer to your main question (I'm a screen user myself, never felt the need to move to tmux), but a comment on: However, since it is time consuming, so I wrote a shell script to do: cd foo/bar ...
user avatar
2 votes

Find recursively minimum one *.flac file, if no *.cue file in same dir print directory name

You can easily do that with zsh globs alone: has() ()(($#)) $REPLY/?*.$1(NDY1) print -rC1 -- **/*(NDFe['has flac && ! has cue']) Remove the Ds if you want to ignore the hidden files/dirs. ...
user avatar
1 vote

Rookie Question: Regex in ZSH Script

zsh has some builtin support for regexp matching (both ERE and PCRE), it also has extended glob operators that go beyond regexps. No need to use that antiquated and broken by design expr command (...
user avatar
0 votes

Rookie Question: Regex in ZSH Script

expr output is the number of characters that matched, did you try printing paperno variable ? I don't think it gives you the spected output https://www.computerhope.com/unix/uexpr.htm May be the ...
user avatar
  • 1
0 votes
Accepted

What's a clean way to run a specific command C for each line L of a given file F and then move every L where C(L) ran unsuccesfully?

With zsh, you could do: while IFS= read -ru3 url; do curl -- $url print -ru $(( $? ? 4 : 5 )) -- $url done 3< urls 4> bad 5> good That way, the bad and good files are opened only once ...
user avatar
1 vote

What's a clean way to run a specific command C for each line L of a given file F and then move every L where C(L) ran unsuccesfully?

Using bash, you can loop for the urls and test the curl command, --fail option of curl seems to be good for use inside scripts, see: How to check whether a command such as curl completed without error ...
user avatar
  • 6,305
2 votes
Accepted

ZSH: How to set an associative array name and content dynamically?

set -A array value1 value2 is the ancient ksh syntax from the early 80s¹ for defining plain arrays. It's not defining associative arrays and is only supported for compatibility with ksh88. The k and ...
user avatar
0 votes

How to run windows executables from terminal without the explicitly specifying the .exe extension?

For bash version of command_not_found_handler, see https://github.com/Microsoft/WSL/issues/2003#issuecomment-618655416 command_not_found_handle() { cmd=$1 shift args=( "$@" ) ...
user avatar
0 votes

How to cd automatically after git clone?

All of the answers so far seem overly complicated. This works for SSH URIs and any other way of cloning because it simply uses the fact that the thing you just cloned is going to probably be the last ...
user avatar
  • 101
0 votes

Which file(s) are being sourced while opening a terminal on Mac?

It depends on which shell (bash, zsh, etc.) your terminal starts up when you open it. For example: Bash startup files Zsh startup files
user avatar
0 votes

zsh in tabby separate history for each tab

If you want to keep your tabs’ histories separate even after a restart, then you will need to declare a different $HISTFILE in each tab, because (as mentioned in the documentation of the fc command): ...
user avatar
4 votes
Accepted

zsh: how to get associative array length?

Unless you had run typeset -A test beforehand, that will have assigned elements of a plain array, not an associative array. zsh arrays like the arrays of most shells and languages (the only exception ...
user avatar
0 votes

How to get a shorter Path prompt in powerline10k / zsh?

You could do something like: $ set -o extendedglob -o promptsubst $ PS1='${${${PWD//#(#b)$HOME(|\/*)/🏡$match[1]}//(#b)([^\/])([^\/]#)\//$match[1]:u/}//\%/%%}$ ' 🏡$ cd install/cvs/oh-my-zsh 🏡/I/C/oh-...
user avatar
-2 votes

Using OR patterns in shell wildcards

You can pipe ls with grep as below aashutosh@ubuntu:/tmp$ ls -ltrh total 0 -rw-rw-r-- 1 aashutsh user 0 May 9 02:55 noon.txt -rw-rw-r-- 1 aashutsh user 0 May 9 02:55 night.txt -rw-rw-r-- 1 aashutsh ...
user avatar
0 votes

How to get a shorter Path prompt in powerline10k / zsh?

I've make this test : pwd | awk -F/ 'BEGIN{ ORS="/" } END{for (i=1; i<=NF; i++){print $i}}' result : /opt/tools/intel/oneapi and then this one : pwd | awk -F/ 'BEGIN{ ORS="/" } ...
user avatar
  • 1
13 votes

Different behaviour of subshells and && in bash vs zsh

You can get a similar thing in Bash: $ echo $$ 26328 $ ( /bin/sleep 1234 ) $ ps -o pid,ppid,stat,args -C sleep PID PPID STAT COMMAND 26473 26328 S+ /bin/sleep 1234 What Bash does there, is that ...
user avatar
  • 115k
0 votes

How to get a shorter Path prompt in powerline10k / zsh?

You can create links ln -s pokemon P Then you can either do cd pokemon or cd P and you would get into the same directory.
user avatar
  • 1,198
1 vote
Accepted

How can I suppress *:// from tab completion suggestions for 'open'?

According to your output, open is an executable in your OS X system. So, to modify its completion syntax, you'd need to figure out where the completion function resides and modify it (I have not been ...
user avatar
3 votes
Accepted

zsh - How do I prepend a string to every element of an array?

A few options: Using the ^ operator which is intended for that (reminiscent of rc's ^): ARRAY=(my_$^ARRAY) Or to make that kind of expansion the default (in the style of rc or fish): set -o ...
user avatar
0 votes

opening default path for root user

You could be put a cd ~/Downloads/owt command in your ~/.zprofile file (which is run at login). Be warned that this may confuse software (or people) that expects to start in your home directory by ...
user avatar
  • 138
1 vote

match number range with non significative zeros in zsh

If it's matching you want, as opposed to generating a list of files regardless of whether they exist or not, use the <x-y> glob operator: print -rC1 -- booklet-<79-256>.pdf <79-256> ...
user avatar
0 votes

Have backticks (i.e. `cmd`) in *sh shells been deprecated?

As a note, your title is a little misleading and different from your question, so let's also answer the question in your title (and in no way disagree with the correct answers regarding just the sh/...
user avatar
0 votes

match number range with non significative zeros in zsh

Simply do in zsh: ls booklet-{079..256}.pdf Test it, it works!
user avatar
  • 930
2 votes
Accepted

evaluate terms in zsh without a command

Intercepting a command before it's executed is possible, but that's too late: the command has already been parsed and aliases have been expanded. So for example 2 * 3 would appear as the command not ...
user avatar
4 votes

Error while trying to source a .zshrc file

You're missing / Your command source ~.zshrc tries to lookup the home directory for a user called .zshrc. The source command would presumably attempt to execute that user's home directory - and fail. ...
user avatar
  • 89.1k
0 votes

Why ZSH ends a line with a highlighted percent symbol?

Explanation: The percentage sign (%) at the end of a line indicates a missing newline character (\n). For example, printf "foo" results in foo%. Adding a newline character to the string, ...
user avatar
1 vote
Accepted

Variable Scope in ZSH: How to access global variables from within function?

Your functions will see the variable that you have set earlier (and exported or not) provided they haven't been set in a subshell or not declared local to some function that has since returned. Your ...
user avatar
2 votes

zsh parameter substitution

I've no idea how that's supposed to work. Assignments don't take the $ sign on the left, so $1=$PWD would not be recognized as an assignment, and would instead just expand both variables and then try ...
user avatar
  • 115k
1 vote
Accepted

zsh: How to retrieve the previous command line?

zsh offers a plethora of options for retrieving previous command lines from its history. Here’s just a small selection of these: Press Up Arrow to step through previous command lines. Press Alt. to ...
user avatar
3 votes

string substitutions: all occurrences

There are many answers, but none of them are comprehensive, so I felt like adding an answer that sums it all up. Lower/Uppercasing If you are trying to uppercase the string, the simplest way is to use:...
user avatar

Top 50 recent answers are included