Hot answers tagged

51 votes
Accepted

What's wrong with var=$(</dev/stdin) to read stdin into a variable?

(and no, for once, this is not about the missing quotes around $(...)¹). The $(<file) operator That Korn shell operator (also supported by zsh and bash) is described at length at Understanding Bash&...
10 votes
Accepted

Obtain a list of files in Terminal in same order as in Finder

ls and shell globs sort file lists lexically by their name by default. The GNU implementation of ls has a -v option for version sort which would help you here, but the ls in macos has no equivalent (...
4 votes
Accepted

Why does variable expansion in commands not work in ZSH but it does in BASH?

It's almost always the wrong approach to stuff several separate strings (arguments) into a single string, at least if you need to extract those separate strings again. What you're doing works in the ...
  • 282k
3 votes
Accepted

How can I/Should I default flags when running a command?

I am really surprised by that other post you mentioned, as it can be very misleading. Just because an alias doesn't use parameters doesn't mean that aliases cannot set parameters. Of course you can ...
  • 464
2 votes

MacOS terminal issues

Put space between export PATH="$PATH:/Users/randus/Library/Application Support/JetBrains/Toolbox/scripts" and eval "$(/opt/homebrew/bin/brew shellenv)" Steps: nano /Users/randus/....
  • 21
2 votes
Accepted

Reverse Search (CTRL + R) no longer searching in .zsh_history

This is an issue with fzf integration which was fixed recently in an update to fzf. You can find the relevant issue here: https://github.com/junegunn/fzf/issues/2943 You simply need to update to ...
  • 71
2 votes
Accepted

zsh: ignore symbolic links in completion list returned by _files

A test directory is populated: % cd && mkdir foo && cd foo % touch file1 file2 % mkdir dir1 % ln -s file1 link1 % ln -s dir1 link2 and with the not-symlink glob qualifiers ^ @ the ...
  • 33k
2 votes
Accepted

Loop for each file in directory but not throw error when no files present

By default, the zsh shell will treat unmatched filename globbing patterns as fatal. If you are expecting a glob not to match anything, then you may use a globbing qualifier to make the pattern expand ...
  • 282k
2 votes
Accepted

How to take positional arguments in a function in zsh?

The problem is with your if condition. You should use just one = or you can also use [[ condition ]]. if [[ $1 == "prod" ]]; then PREFIX='https://PROD_URL' fi Or: if [ "$1"...
1 vote

invoking 'man' specify search at command line

$ man zshbuiltins | less -p '^ read' ... Exactly what I want. Beginning of the line, seven spaces, then the name of the command (read), and it takes you right to the command. Built myself a ...
  • 1,893
1 vote

the output between zsh and bash

A variable that doesn't exist in the environment doesn't have any value, so there is nothing there to print. It isn't that variables magically get the value 0, if they are not defined, they are not ...
  • 221k
1 vote
Accepted

Add heredoc (<<) to end of alias within function call

You need the EOF to be the full contents of the line for it to be taken as delimiter. qredshift() { local IFS=' ' psql "host=$host user=$redshift_uname dbname=$redshift_dbname port=$port ...
1 vote
Accepted

How can I configure zsh completion to exclude `.` and `..`?

The same question you provided has the answer: According to a comment of this answer Those are never shown in the completion list unless your .zshrc contains something like this: zstyle ':completion:*...
1 vote
Accepted

change file extensions as with 'ren' command in DOS?

For a single file, you can use brace expansion to construct a command line to rename a file, where only one part of the file name changes. mv /Users/dir/dir1/moredir/long/foo.{txt,yaml} The general ...
1 vote

zsh glob qualifier with negated null glob works like it should with null glob

The _files function is a wrapper around _path_files and the _path_files code involves not just a glob but various other logic and zstyle settings; adding a -g glob influences what the pats array ...
  • 33k
1 vote

Source script with user input

ZSH is not bash; the shells have incompatible read builtins. bash: -e If the standard input is coming from a terminal, readline (see READLINE above) is used to obtain the line. Read- line ...
  • 33k
1 vote
Accepted

Source script with user input

I don't quite get why it isn't working, it works fine for me: $ source foo.sh User: terdon Password: ~ $ ## I entered the password here, you can add an echo to clear the line $ echo "$...
  • 221k
1 vote
Accepted

Within an AWS CLI command, add the ISO 8601 datetime

You could use jq to insert the date into the json object: aws dynamodb put-item \ --table-name tasks \ --item "$( jq -c '.created_at.S=(now|todate)' << 'EOF' { ...
1 vote

Within an AWS CLI command, add the ISO 8601 datetime

As the error message highlights, the JSON is invalid. So, as to be expected, the command you wanted to be executed never was – how was the shell supposed to know which parts of the command line you ...
1 vote
Accepted

correct way of writing functions in zsh

function-name() command is one of several function definition syntaxes supported by zsh, the one from the Bourne shell from the early 80s, so that part of your code is fine. If you get a parse error ...
1 vote
Accepted

paste command puts data from csv files vertically line by line instead of horizontally next to each other

Most likely, your original files have \r\n end of lines. If it is so, the final file would have an extra \r between each line segment. Try using tr: paste -d "," *csv | tr -d "\r" &...
  • 2,373
1 vote

Tar Copy while skipping over a certain file pattern

The Correct command is tar --exclude='**/.*' -cf - . | pv -s $(du -sb ~/test1 | awk '{print $1}') | (cd ~/test2; tar xf -) As @doneals24 posted in a previous comment, the -f option is the name of the ...
1 vote
Accepted

Is it possible for a shell to (automatically) source files after the first prompt is shown?

As you have found out, running commands in the background with & will put them in a subshell, and a subshell can't change variables/environment variables of the parent process. ("can't" ...
  • 175
1 vote

How can I change the umask for one command only?

Another trick is to save the file using install and process substitution. But that only works if the command will output its data to stdout and is only a single file. install -m 600 <(cmd) newfile
  • 11

Only top scored, non community-wiki answers of a minimum length are eligible