All Questions
Tagged with function shell-script
143 questions
3
votes
1
answer
525
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
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 "...
0
votes
1
answer
658
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
325
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
87
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
6k
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
52
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
262
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
88
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
163
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
181
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/...
2
votes
0
answers
753
views
Is valid use 'source' within a function?
Like an introduction: if secondary.sh has
functionX(){
...
}
and primary.sh has - source secondary.sh declared - and its own functions, therefore:
# primary.sh content
source secondary.sh
...
0
votes
0
answers
211
views
Passing one or more files in function in bash
Here I have written a sample bash script, the problem with this is that I am able to successfully pass file to function remFun but I am unable to pass the file unique.txt to function printfile. In ...