All Questions
167 questions
0
votes
2
answers
97
views
How to redirect output from a program that waits for input
Following this post I created my own version of the script, with the difference that user and password are forwarded from the environment variables:
#!/bin/zsh
pamtester login $user authenticate <&...
0
votes
0
answers
19
views
zsh variable expansion [duplicate]
I'm a bit of a noob with *nix and sh vs bash vs zsh specifically. Can someone explain this syntax with shell variables? What syntax do I need to use to get a filename pattern held in a variable to ...
0
votes
0
answers
27
views
Variable Argument Processing - zsh vs. bash [duplicate]
I ran across a problem in one of my scripts when I changed it from bash to zsh. Here is the behavior in bash:
bash-5.2$ X="-v1d -v+1d"
bash-5.2$ echo $X
-v1d -v+1d
bash-5.2$ date $X
Mon Dec ...
5
votes
1
answer
357
views
printf in Zsh does not shell escape exclamation mark
In Zsh 5.9, we can use printf to shell escape a string:
$ printf '%q' 'One! Two'
One\!\ Two
This produces the correct output of escaping the ! and the space. Now let’s make it as a script:
#!/bin/...
0
votes
2
answers
188
views
:q to quit from less and man. Are there other colon-commands in Bash/Zsh?
To quit from man or less, we use :q, like in Vim. But where can I read about this command and probably other similar commands (maybe :w, for example) in Bash or Zsh documentation? help q, help :q, ...
0
votes
0
answers
80
views
What could be causing processes to be suspended?
This excerpt from a shell session says it all:
brandon@Air ~ % brew upgrade rust
...
==> Pouring rust--1.75.0.arm64_monterey.bottle.tar.gz
[1] + 76816 suspended (signal) brew upgrade rust
...
1
vote
2
answers
119
views
Start interactive function definition from shell-script
Using zsh or bash, I want to run a script that may prompt the user for multiple commands and store them as a function, however I'm finding that eval "function $FNCNAME() {" or echo "...
0
votes
0
answers
22
views
How to copy terminal output to a file without using mouse [duplicate]
Say I have a bunch of text in the terminal. I can use my mouse/cursor to copy to clipboard but is there a way to copy the last X lines from the terminal to a separate file using a terminal command?
5
votes
3
answers
756
views
zsh -z test meaning of "+x"
I am new to zsh and have been a bash user for years.
In an example zsh script I see a test:
if [ ! -z ${ZSH_MOTD_CUSTOM+x} ]; then
In bash I would expect:
if [ ! -z "$ZSH_MOTD_CUSTOM" ]; ...
2
votes
1
answer
75
views
Is there a better way to replace the actual shell in a script on a macOS/BSD-like OS?
I am using macOS. I have a shell script that doesn't work with bash but requires zsh. If I accidentally call it with sh (which is a very old bash on macOS) or bash I want it to replace sh or bash with ...
0
votes
3
answers
163
views
Escaped newlines make the code work wrong. Why?
From a Markdown style guide by Google:
Because most commandline snippets are intended to be copied and pasted directly into a terminal, it's best practice to escape any newlines. Use a single ...
0
votes
2
answers
788
views
Bash and other shells $(...) remove the ending newline character [duplicate]
Why the shell structure $(...) removes the ending newline character?
#!/bin/bash
S='a
b
'
printf '%i [%s]\n' "${#S}" "$S"
T=$(printf '%s' "$S")
printf '%i [%s]\n' "...
2
votes
1
answer
465
views
if var='value' then in Zsh: Is it really a valid syntax without semicolon?
The following code works on Zsh 5.8 that I tried, despite the missing semicolon. But is it really a valid Zsh syntax?
#!/bin/zsh
if var='value' then
echo 'then'
fi
Without an assignation that ...
3
votes
0
answers
263
views
Are there any Linux distros with a preconfigured user-friendly shell environment?
I see so many Linux distros all around, and they all come with different look & feels and their own set of pre-installed GUI tools for most standard tasks. The default shell environment, however, ...
0
votes
0
answers
49
views
Compress list of files as their shortest exclusive glob
How can I convert a list of files to the minimum-length glob that expands to those files and no others?
E.g. in a directory
root
├── one
└── two
Then the list root/one:root/two can be converted to ...