Skip to main content

All Questions

Tagged with
1 vote
0 answers
85 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 ...
WGroleau's user avatar
  • 824
3 votes
0 answers
242 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 ...
Stonecraft's user avatar
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 ...
ZJS_Spctr555's user avatar
1 vote
0 answers
293 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, ...
Jack's user avatar
  • 111
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 ...
LukeMA82's user avatar
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 ...
s_dav's user avatar
  • 25
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 ...
Petr's user avatar
  • 3,173
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 ...
comws's user avatar
  • 13
0 votes
1 answer
153 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 ...
Bn.F76's user avatar
  • 134
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 ...
RocketNuts's user avatar
  • 1,172
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 ...
Diego S.'s user avatar
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 ...
ARK's user avatar
  • 450
0 votes
1 answer
456 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 ...
idelara's user avatar
  • 101
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 ...
Henrique Barcelos's user avatar
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 ...
Brad Parks's user avatar
  • 3,066
0 votes
1 answer
1k views

How to determine if a screen is running jobs without attaching to it?

I wrote a zsh script that launches many screen sessions and runs a different command in each of them. When the script is executed there are 72 screens in total, so checking if a job is finished or not ...
Vesnog's user avatar
  • 151
2 votes
4 answers
1k views

How to merge ls commands colors with the output of find or du?

I have a simple alias to list the size of files&folders in cwd. ( including dotfiles in this case , ignoring zero sizes ) du -sh .[!.]* * | sort -hr | grep -v '^0' which can be achieved aswell ...
Nicolai Fröhlich's user avatar
1 vote
2 answers
635 views

tar backup zsh script

Trying to set up a cronjob ran tar script to backup site (without .git and setup folder) every night and upload time stamped archive to Dropbox. It gives me a hard time as archive is created along ...
dzhi's user avatar
  • 117
4 votes
1 answer
3k views

Script-specific autocomplete in shell

I create a lot of little scripts to help me in my every day life. I would like to provide auto-complete for them, specially that I intend to share them with people. Now, I know I can create auto-...
Xananax's user avatar
  • 205
23 votes
2 answers
9k views

Writing shell scripts that will run on any shell (using multiple shebang lines?)

I've just started getting deeper into shell scripting, and I've always just thrown my script in a file, marked it chmod +x and then done /path/to/script.sh and let whatever interpreter is the default ...
swrobel's user avatar
  • 365
5 votes
2 answers
6k views

Efficient way to use all cores in bash or zsh script

If I want to process large number of files with command "do_something" which only can use one core, what's the best way to use all available cores assuming each file can be processed independently? ...
Lissanro Rayen's user avatar
0 votes
1 answer
442 views

zsh expansion modifiers in scripts

I've just found out that ZSH's modifiers only work in interactive scripts, so the following will work correctly on the command line but not from a script (the script ignores the modifier and echoes ...
Gareth's user avatar
  • 317
2 votes
1 answer
7k views

Deleting a file if it exists or not

Here is a part of my zshrc file. ## Most Frequently used settings # ls alias ls='rm .DS_Store; echo --------------${PWD##*/}--------------; ls -1FGu' alias l='ls -A' I want to delete .DS_Store, ...
SurenNihalani's user avatar
2 votes
1 answer
8k views

Creating a link for all files in a directory to home

I am trying to write a small zsh (bash compatible) script to take each file in ~/.oh-my-zsh/links directory and creates a hard link for it in ~. I am not sure how to do this. Would this be correct? ...
SurenNihalani's user avatar
0 votes
3 answers
1k views

High performance perforce sync

I am trying to do p4 sync folder/... It's not very fast and it's using only 2% of the CPU. I am not happy with the performance. I am trying to write a function in bash, given a parameter n, it forms ...
SurenNihalani's user avatar
0 votes
1 answer
153 views

Diff between files in different directories

I have the follow directory structure ./goodboys/a.txt ./goodboys/b.txt ./badboys/a.txt.boy ./badboys/b.txt.boy I am using zsh. I want to diff all *.txt in goodboys with *.txt.boy in badboys. I am ...
SurenNihalani's user avatar
5 votes
2 answers
2k views

How to search *upwards* for file? (reverse find)

I'd like to search "upwards" for a file in shell script, e.g. check $PWD, then $PWD/.., then $PWD/../.., etc. until hitting the root. Before I go and roll my own, is there some builtin bash/zsh/find ...
Joseph Garvin's user avatar
1 vote
1 answer
1k views

Under zsh, looking to use `tr` to search and replace a single character with multiple characters

I want to replace "Blah: whatever" or "Blah/Whatever" with "Blah--Whatever" I have this: NEW=`echo ${OLD} | tr '[:/]' '--'` echo ${NEW} I suppose it's taking the 2 dash characters to mean 1 letter ...
Roy Rico's user avatar
  • 5,948
3 votes
4 answers
3k views

Loop: Start program and kill after time out

for debugging reasons I want to spot one of those bugs showing up just occasionally. Therefore I want to code a while loop in the shell starting the program (if it will segfault => that's what I want)...
math's user avatar
  • 2,653
2 votes
2 answers
2k views

On OS X, how do I start Cocoa emacs *and* bring it to front?

I wrote a little zsh function to allow me to run emacs from the command-line: function emacs() { /Applications/Emacs.app/Contents/MacOS/Emacs $@ & } This works perfectly, but it seems to ...
Jason Baker's user avatar
  • 8,672