All Questions
Tagged with zsh shell-script
30
questions
1
vote
0
answers
83
views
Zsh handling of substring changed?
I have over a thousand directories holding MP3 files and text. I work on one directory each day, assisted by zsh scripts. I mostly use zsh on command line and in scripts. The paths are in the form ...
3
votes
0
answers
230
views
Is there a good way to write a shell script compatible with both bash and zsh that addresses array elements?
The fact that bash is 0-indexed and zsh is 1-indexed can cause problems. For example the following will work as intended with bash, but not zsh (PS I am aware that I don't NEED to use an array for ...
0
votes
1
answer
73
views
zsh on MacOS catalina 10.15.17
I'm having a little trouble putting this all together...
I want to make a simple shell script to organize and sort around 60 GB worth of music and movie files that are spread out over 3 or for 4 ...
1
vote
0
answers
281
views
Source multiple files in background/parallel (ZSH)
For various reasons I would like to be able to source a series of files in background and wait for them all to finish:
source ./my_file_1.sh &
source ./my_file_2.sh &
...
# etc
wait
But, ...
1
vote
2
answers
2k
views
Change the default location of zsh completion cache files for macOS
I'm trying to change the default location of the zsh completion cache files in macOS. I have read the zsh documentation on completion which say's "alternatively, an explicit file name can be ...
1
vote
0
answers
54
views
$RANDOM, not so random [duplicate]
I want to print out a random number and encrypt it, like so: echo $RANDOM | sha256sum.
I would expect this to take the standard output of echo $RANDOM and pipe it into the encryption function. However ...
4
votes
1
answer
3k
views
How to always execute a command when a shell script function finishes?
I need to write a zsh function with multiple exit points and execute the same clean-up command at every one of them:
function foo {
if ... ; then
...
run_cleanup
return
...
1
vote
2
answers
2k
views
Issue with running a shell script without using 'sh' on macOS Monterey
I'm new to shell scripting and generally the usage of Terminal.
I recently made a script.sh that I want to use by just typing its name without the full path.
So, I wrote the path of the directory into ...
0
votes
1
answer
152
views
How to access highlighted text with pbcopy?
How can I "catch" text that has been selected (highlighted) via shell script? It was suggested to use pbcopy. The script would be idle in the background and when a certain key combination is pressed ...
6
votes
1
answer
5k
views
How or where to define global functions to be used in bash, zsh, sh scripts?
Say I have these three script files: (all 3 are executable)
bash-test.sh:
#!/bin/bash
HelloFromBash RocketNuts
zsh-test.sh:
#!/bin/zsh
HelloFromZsh RocketNuts
sh-test.sh:
#!/bin/sh
HelloFromSh ...
3
votes
1
answer
2k
views
Running functions that were declared outside my shell script
Currently my ZSH has some sourced functions, for instance:
% declare -f
... a lot of shell functions appears here.
I'm currently writing a shell script that will call a specific function from ...
2
votes
1
answer
3k
views
execute function in different shell
I usually zsh. I want to execute a function in bash and return back to my original shell. I can do this manually, but I want to automate it. How can I do that?
For example, I am on zsh.
I want to ...
0
votes
1
answer
454
views
Running nano from function in config file (function in zshrc) does not save changes
I am using zsh as my shell and I am trying to achieve this:
In my .zshrc file I want to have a function that modifies my .zshrc, saves it and reloads it.
So far I have to functions (in my .zshrc ...
8
votes
2
answers
18k
views
Using arrays in ZSH
I have the following statement:
TOKENARRAY=($TOKEN)
$TOKEN is a numeric variable.
If I try this:
echo ${TOKENARRAY[0]}
it shows me an empty string.
If I do:
echo ${TOKENARRAY:0}
it shows me ...
7
votes
1
answer
2k
views
tmux - get pwd of another pane in a bash script?
Is there anyway to find out information about the current working directory of any pane from within a tmux session?
I'd like to write a bash script that changes the directory of the current pane to ...