All Questions
19 questions
4
votes
2
answers
220
views
How to make the (N) patterns of the zsh eatable by bash?
I am trying to develop a script which runs (and, ideally, does the same :-) ) in zsh and Bash. Problem is, that at a point, the zsh-specific part contains a pattern ending with (N). So: this_pattern*(...
0
votes
1
answer
907
views
Shell script: How to prepend env variable with prefix only if environment variable is defined?
Given command that requires flag --flag. We want to insert this flag only when the value of the flag is provided as environment variable VALUE.
I tried the following:
echo "command ${X+--flag ${...
2
votes
1
answer
840
views
Does bash (or zsh) "officially" mandate the use of tabs for indentation in scripts?
I recently came across the following statement (source; emphasis added):
For shell scripts, using tabs is not a matter of preference or style; it's how the language is defined.
I am trying to make ...
0
votes
3
answers
242
views
Writing a zsh script that goes in order
I am using Big Sur and I am trying to write a script that will make a package run (the package is XSPEC, a spectral fitting package from NASA), and then run commands run in that package. I start with ...
2
votes
1
answer
2k
views
Delete multiple files using rm with only one confirmation for everything (rm -i)?
I have an alias rm='rm -irv' and I want to delete a bunch of files and/or directories but I only want 1 confirmation message like rm: descend into directory 'myfolder'?
I don't mind confirming for ...
0
votes
1
answer
3k
views
zsh: repeat: command not found when executing zsh script
I just wrote a little zsh script named test.sh (and also made it executable) but I get the following error after executing sh test.sh :
repeat: command not found
Here is the script:
#!/usr/bin/zsh
...
0
votes
1
answer
2k
views
How do I check the result of a command for an output vs no output in zsh if statement?
I would like to compare 2 files using diff and then if it returns nothing then echo "no diff" else display the difference. My current if statement only works if there is no difference but if there is ...
1
vote
3
answers
2k
views
How do I grep from one character or pattern to another?
I want to grep a string from a given character or pattern until another given character or pattern instead of the entire line.
For example:
$ > echo "The brown fox jumps over the lazy dog" | grep ...
1
vote
2
answers
702
views
Function to go forward one directory, if possible?
I use below code snippet (by pressing alt-h), to go backward one level of current directory.
up-dir() {
cd ".."
zle reset-prompt
}
zle -N up-dir
bindkey "^[h" up-dir
I want similar ...
1
vote
1
answer
135
views
Zsh: =() substitution with executable permission
I need to give an executable file to this command:
aria2c “some-url” —on-download-complete =(echo “!#/usr/bin/env bash
touch success”)
Is this possible? If not, can I implement some helper functions ...
1
vote
1
answer
114
views
How to write a function that reliably exits (with a specified status) the current process?
The script below is a minimal (albeit artificial) illustration of the problem.
## demo.sh
exitfn () {
printf -- 'exitfn PID: %d\n' "$$" >&2
exit 1
}
printf -- 'script PID: %d\n' "$$" ...
4
votes
1
answer
830
views
GNU Parallel doesn't run the jobs until the program has exited
When I run (rss-notifier's code is included at the end),
rss-notifier.zsh https://www.wuxiaworld.com/feed/chapters ".*"|parallel --null -k --lb echo {}
I get,
Title: Sovereign of the Three Realms - �...
0
votes
1
answer
322
views
How can I limit the times a script runs from within tmux?
I have a script which pings a website and tells me how much time I've worked in the week. I want that to be in the status bar in my tmux.conf, but I'm having the issue of the script running about once ...
0
votes
1
answer
108
views
Count amount of files/directories in SELECTED directory
I'm trying to make a script that counts files/directories in a specific directory but I have a problem. Here's the script that works for a current directory (count.sh):
ARG3=${1:-d} #default value - ...
2
votes
2
answers
2k
views
How to run a ZSH glob command recursively for sub-directories
I have a ZSH glob command that removes anything but the newest 10 directories within a folder.
#! /bin/zsh
cd /path/to/backups/pod1 && rm -rf ./*(Om[1,-11])
However, this is limited to just ...