All Questions
Tagged with shell-script function
145 questions
0
votes
1
answer
46
views
How to keep a local function private in a zsh `autoload` module?
I want to define a helper function in a zsh autoload-ed module. The problem is, if I just define in my my_autoloaded_fn file such as
function helper {
# ...
}
helper a
helper b
the name helper ...
2
votes
4
answers
178
views
Is there a Bash variable containing the name of the previously executed function?
I want to line up a couple of Bash functions based on the success or failure of the execution of the preceding function.
If something fails, I want to print an error message: function_x has failed.
...
3
votes
1
answer
592
views
Strange variable scope behavior when calling function recursivly
EDIT: sorry. this is my first question here.
Here is a minimal working example
#!/bin/bash
#
count=0
function something() {
if test -f "$1"; then
# is a file
((count++))
...
1
vote
2
answers
136
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 "...
0
votes
1
answer
701
views
Running a function as process with a set process name or id
I have a bash script set up to monitor a number of UDP streams and convert it into actionable data. My problem is that I need to set the script to periodically check to see if the stream capture is ...
2
votes
4
answers
351
views
Function's comment is not printed out when putting it before the function's header
A good and well-established guideline for commenting a shell function is to put it before the function's header. I am trying to follow these guidelines as much as I can, but this convention makes it ...
0
votes
2
answers
101
views
How to add corresponding strings to a file from another file that it shares a field with?
I have two files that both have the field "tumor id". Both are comma delimited. I need to add a field that is uniquely in file 2 to file 1, and I want to add the lines of the field according ...
0
votes
1
answer
8k
views
How to return from bash functions the right way?
This script, which i source in my terminal, offers the function _cphetzner, that is used to create a git repository. This function uses another function _feed_variable that prompts user for missing ...
0
votes
2
answers
64
views
How to pass commands around?
I have this simple script, which does nothing more than:
check if an email matches a specific pattern
in that case, add a tag to a taglist
before quitting, print that taglist
set -e
lista_tag=()
...
0
votes
2
answers
294
views
Compare Execution Times of Two Functions
I am attempting to write a function which will take two commands as inputs, time the executions of both of them, then output those times to a text file. After reading this post, I got most of the way ...
1
vote
0
answers
94
views
startx function/alias has wrong arguments if not prefixed with exec
For context, my file/directory structure and contents are mostly copied from how it is in Luke Smith's dotfiles (voidrice). Also, the "..." lines in the code blocks aren't code and represent ...
0
votes
0
answers
10
views
Linux regex in substitution of a string passing argument from CLI [duplicate]
I have wrote the simple script
#!/bin/bash
progname=$1
sed -i.bak 's/#define SFFX "_.*"/#define SFFX "_$progname"/' path/to/file
In order to find a preprocessor directive in a C ...
0
votes
1
answer
175
views
How to create functions using for loops?
I'm trying to use a for loop to create functions for choosing passwords in my Arch install script (based on easy-arch) using the following code (which uses this se answer for repeating prompts and ...
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
1
vote
1
answer
201
views
zsh parameter substitution
This page has a demo function as follows:
~inews> namedir () { $1=$PWD ; : ~$1 }
But when I try it on my machine, it produces the following error:
namedir: no such file or directory: test=/home/...