All Questions
11 questions
2
votes
0
answers
47
views
Can't unalias then redefine as a function in the same conditional [duplicate]
Here is a simplified implementation of an issue in my bash/zsh aliases file:
alias foobar='echo bar' # this is out of my control
if true; then
unalias foobar
echo we got inside the conditional
...
1
vote
2
answers
119
views
Start interactive function definition from shell-script
Using zsh or bash, I want to run a script that may prompt the user for multiple commands and store them as a function, however I'm finding that eval "function $FNCNAME() {" or echo "...
1
vote
1
answer
245
views
Run `git commit -m` with single quotes in zsh
I sometimes use characters such as ! and $ in commit messages, they need to be manually escaped, but not if you use single quotes like this git commit -m 'My $message here!'. I tried to write a ...
5
votes
1
answer
2k
views
zsh: pass variable by reference, and modify its value (like bash's local -n namerefs)?
Is it possible to pass a variable to a zsh function, and modify its value without using eval? I came across a bash way to do that: local -n: https://stackoverflow.com/a/50281697
0
votes
1
answer
53
views
In a bash/zsh function how do I do something, then depending on the output, do A or B?
This function looks through each local git repository in folder ~/src, and does git pull on it. More and more I keep getting an error
Please commit your changes or stash them before you merge.
...
0
votes
1
answer
499
views
Is there a zsh command to output shell function code, like `type` in bash [duplicate]
In bash, when I'd like to have a glimpse at what an already defined shell function does, I can:
$ type myFunctionName
For a variable myFunctionName, it provides me with the type of the variable (a ...
0
votes
2
answers
225
views
How to define the name of a bash function to be a regex
I've searched around and can't find an answer.
I want to define a function like this
function \d{2} () {
echo $1_or_smth
}
Then if I say in my terminal
12
I want it to echo 12 back.
3
votes
1
answer
638
views
Are there any conventions for the name of global variable that holds function's result?
A typical way for a shell function to "return" its result is to assign it to some global variable.
Is there any convention/best-practice on the name of this variable?
21
votes
2
answers
9k
views
Test for function's existence that can work on both bash and zsh?
Is there a way to test whether a shell function exists that will work both for bash and zsh?
1
vote
0
answers
3k
views
zsh function: maximum nested function level reached [duplicate]
Consider this simple function I am trying to add in my .aliases (dnf is Fedoras newest replacement of Yum):
function abc() {
dnf search something
}
It works well on Bash but I get the following ...
21
votes
2
answers
12k
views
Shell valid function name characters
Using extended Unicode characters is (no-doubt) useful for many users.
Simpler shells (ash (busybox), dash) and ksh do fail with:
tést() { echo 34; }
tést
But bash, mksh, lksh, and zsh seem to ...