All Questions
13
questions
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 ...
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
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
...
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 ...
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 ...
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 ...
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-...
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 ...
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?
...
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?
...
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 ...
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 ...