Skip to main content

All Questions

Tagged with
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
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
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
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
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
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
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
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