The tag has no usage guidance.

learn more… | top users | synonyms

-1
votes
1answer
32 views

Adding Function to array based on index [on hold]

I am using Bash. I am trying to add a function to an array. I tried using: if [ $CONTROL -eq 0 ]; then array[$index]+=`function_name1` fi if [ $CONTROL -ge 1 ] && [ $CONTROL -le 20 ]; ...
1
vote
1answer
37 views

Segmentation fault when calling a recursive bash function

I have hundreds of multiple folders which contains thousands of zip files which contain nested within the zip files like show on three below start tree structure 012016/ ├── 2016-01 │   └── 2016-01 │ ...
1
vote
2answers
41 views

Syntax Error near Unexpected Token in a bash function definition [closed]

Forgive me; I'm pretty new to bash files and the like. Here is a copy of my .bashrc: alias k='kate 2>/dev/null 1>&2 & disown' function kk {kate 2>/dev/null 1>&2 & disown}...
1
vote
0answers
29 views

Save return value from a function in one of its own parameters

Function: Func1() { str1=$2 $1=$str1 } Call function: local var1 Func1 var1 "Helle World" echo $var1 I know this will work but I guess it's not very "pretty": Func1() { str1=$2 eval ...
3
votes
0answers
36 views

SIGINT is not cleaned up in “${FUNCNAME[@]}”

Take the following script, interrupted by keyboard input ^C as shown: $ function a() { echo "Performing"; sleep 10; echo "Performed"; } $ a Performing ^C $ echo "${FUNCNAME[@]}" a source If we ...
6
votes
1answer
58 views

Displaying usage comments in functions intended to be used interactively

I have a number of functions defined in my .bashrc, intented to be used interactively in a terminal. I generally preceded them with a comment describing its intended usage: # Usage: foo [bar] # Foo'...
1
vote
1answer
31 views

$* variable of zsh function leads to unexpected results

I have this function (defined inside my ~/.zshrc): function graliases { if [[ "$#*" -lt 1 ]] then echo "Usage: graliases <regex>" else echo "$*" grep -E '*"$*...
1
vote
2answers
31 views

VIM: function that checks if external program is running

Using a vim function, I would like to check if a program is running using pgrep, and if it is not running then do something. In particular, I want to achieve something like this: function! ...
1
vote
0answers
17 views

Returning an array from a ksh93 function

I would like to return an array from a function in ksh93. At this point, using the following method, the contents of the array are passed as a single element even though, in the fonction, the array ...
1
vote
1answer
24 views

Caller-aware function in bash

I have a function (=callee) that should effectively declare and assign a couple of variables in its caller. It should also be able to tell what it's caller's name is. For now I achieve the former by ...
0
votes
1answer
38 views

retrieve numbers with 0 for a single int value

In my script, I need to get a 0 for numbers <=9. When the user types any number, I add 5 to it and if the result is less than 9, I need to print a 0 in order to have a 2-digit number (like 07,08,09 ...
1
vote
1answer
55 views

Script to send mail using function

I am trying to write a bash script with a function which you use to send an email from the command line to an address and include a Cc address, a subject line, and an input file. For example, if the ...
0
votes
0answers
81 views

zsh function: maximum nested function level reached

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 ...
4
votes
4answers
55 views

Does \ work for escaping functions?

I have a function defined in my .bashrc that I would like to bypass: function func() { // func } export -f func When I run env -i func I can access the func command without the function in the ...
0
votes
2answers
47 views

Why should not I update to most recent kernel immediately after release [closed]

Question intended for system administrators. Consider system running a old but working kernel and all the required functionality is available. (Ubuntu 12.04 LTS specifically with kernel 3.2) Then a ...
0
votes
3answers
105 views

Defining bash function dynamically using eval

I'm trying to define a bash function dynamically using following code: delegate_function() { echo "output from delegate"; } eval "parent_function() { echo $(delegate_function); }" The intent is to ...
1
vote
2answers
67 views

Scope of Local Variables in Shell Functions

After reading 24.2. Local Variables, I thought that declaring a variable var with the keyword local meant that var's value was only accessible within the block of code delimited by the curly braces of ...
0
votes
2answers
54 views

Please explain below bash function

I find this function online. It's does creating a directory and changing to directory. But I want to know every part of it. function mkdircd () { mkdir -p "$@" && eval cd "\"\$$#\""; }
1
vote
3answers
90 views

Using time on bash functions (not commands)

How can one measure individual calls to bash functions from inside the bash file. I have a program that I call using the command eclipse -b col_solve.pl -e "myPred" This call outputs some ...
1
vote
3answers
42 views

case statement not behaving as expected (fuzzytime() function)

FuzzyTime() { local tmp=$( date +%H ) case $((10#$tmp)) in [00-05] ) wtstr="why don't you go to bed" ;; [06-09] ) wtstr="I see your very eager to start the day" ...
0
votes
1answer
14 views

Is there a Fish Function I can make to eliminate leading “$”/“#” from commands copied from sites?

Sometimes when I'm copying and pasting a command from a site, I accidently copy the leading "$" or "#" by accident. Is there a Fish Function I could make that would check if one of those is included ...
0
votes
2answers
19 views

ZSH function to edit a file based on an input at the cli

I need to set up a function in zsh that would edit a different file based on some input at the command line. I want to simplify my aliases so I don't have multiple aliases to do the same thing but ...
2
votes
4answers
66 views

How to catch and handle nonzero exit status within a Bash function?

Say I have the following (pointless) Bash function: myfunc() { ls failfailfail uptime } I run it as follows: myfunc || echo "Something is wrong." What I want to happen is ls runs (as ...
5
votes
1answer
62 views

Cannot grep jobs list when jobs called in a function

I can grep the output of jobs, and I can grep the output of a function. But why can't I grep the output of jobs when it's in a function? $ # yes, i can grep jobs $ jobs [1]+ Running vim [2]+...
2
votes
2answers
35 views

Get specific result from function

Is there a way to return a specific value in an echoing function? return allows me to return an exit status for the function. I need to return a more sophisticated data structure such as an array, or ...
0
votes
1answer
61 views

netcat daemon for calling functions in sh script

I'm new to shell programming and I have created a script that opens a connection to a server of mine. I want to have this script listen for an input from a client node and use that to run a function. ...
0
votes
0answers
16 views

How do I compute the angle of the 2D 3 points ? [[ In kernel space]

I 'm looking at the touch driver 's Kennel. Sometimes a touch is bouncing County singah appear. Collected by recruiting three points 'm trying to calculate the angle between . But there is no such ...
0
votes
0answers
29 views

How do i run multiple scripts within another script in the same directory?

Last part of a project and I've created 3 scripts already that do the following, but I now need to run them within a 4th script as if it was one program. Below are the instructions as well as the code ...
1
vote
2answers
40 views

Optional parameters in bash function

I have a function for quickly making a new SVN branch which looks like so function svcp() { svn copy "repoaddress/branch/$1.0.x" "repoaddress/branch/dev/$2" -m "dev branch for $2"; } Which I use to ...
1
vote
1answer
44 views

how to get or reflect the name of the bash function which is called? [duplicate]

i did not yet found a solution to this. Anyone a hint? i sometimes write bash functions in my shell scripts and i love to have my scripts being verbose, not just for debugging. so sometimes i would ...
1
vote
1answer
33 views

Which shells have functions where “local” does not alter exported variables for child processes?

In the example below, an exported variable is re-set as local in a function. Bash, Zsh, Fish don't pass on the original value to the child process. Are there any shells that make local affect the ...
3
votes
2answers
135 views

How to make a function available to the command `parallel` (GNU)?

In Bash, let's consider a function that does nothing but echo the argument followed by "is an integer". f () { num="${!1}"; echo $num is an integer; } number=12 f number # 12 is an integer I would ...
1
vote
1answer
44 views

How can I source several files into my .bashrc?

I want to write my functions each in separate files, for easier version control, and source the whole lot of them in my .bashrc. Is there a more robust way than e.g. . ~/.bash_functions/*.sh ?
0
votes
0answers
21 views

Listing available functions [duplicate]

I have a function defined on my .bashrc that allows me to mkdir and cd into a folder, which I call mkcd. I could write the same thing using an alias, or as a script. For aliases and scripts, I can ...
0
votes
2answers
40 views

bash script function argument problem [duplicate]

Not sure why this is producing error. This is a test code emulating my real code. I want to write a wrapper for find and want to allow for any argument, so I'm wrapping each arg in single quotes. #...
3
votes
1answer
52 views

zsh: Tab completion for function with Git commands

In zsh I am using the following function to delete a local and a remote branch with one command: gpDo () { git branch -d "$1" && git push --delete origin "$1" } Currently, auto-...
3
votes
3answers
173 views

Executing a Bash Script Function with Sudo

I have a script that does a number of different things, most of which do not require any special privileges. However, one specific section, which I have contained within a function, needs root ...
2
votes
2answers
133 views

POSIX print function definition

Bash can print a function defintion: $ bash -c 'y(){ echo z; }; export -f y; export -f' y () { echo z } declare -fx y However this fails under POSIX Bash, /bin/sh and /bin/dash: $ bash --posix ...
4
votes
4answers
188 views

show only physical disks when using df and mount

When I use df or mount, I'm most of all interested in physical disk partitions. Nowadays the output of those commands is overwhelmed by temporary and virtual filesystems, cgroups and other things I am ...
1
vote
1answer
154 views

Bash FUNCNAME equivalent in Dash

Bash can print the current function name: $ bash -c 'g(){ echo $FUNCNAME; }; g' g However Dash cannot use FUNCNAME: $ dash -c 'g(){ echo $FUNCNAME; }; g' It is possible to access the current ...
4
votes
3answers
117 views

Using “@” as a bash function name

Is it possible to use the "@" symbol as a function name in a bash script? The following does not work: function @() { echo hello }
0
votes
1answer
35 views

Pipe encrypted archive to uploader

Assume, I do archive several files with this functions: gen_password () { gpg --gen-random 1 "$1" | perl -ne' s/[\x00-\x20]/chr(ord($^N)+50)/ge; s/([\x7E-\xDB])/chr(ord($^N)-93)/...
3
votes
3answers
152 views

How to determine callee function name in a script

To make it short, doing something like: -bash$ function tt { echo $0; } -bash$ tt $0 will return -bash, but how to get the function name called, i.e. tt in this example instead?
1
vote
2answers
125 views

How do you list all functions and aliases in a specific script?

I have a bash script that's getting quite long. It would be nice if I could list all the functions in it. Even better would be listing the name of the function and any documentation about it's usage,...
3
votes
3answers
176 views

Recursive Function not Working

I know that this is a ridiculous idea, but I'm trying to get a script to work that branches through every directory on the file system. The file's name is "Everywhere.sh". Here's the code: #!/bin/...
0
votes
1answer
28 views

display array in a function - not working

What am I missing here? I have created a simple array: declare -a appArray=( "item1 -a -b" "item2 -c -d" ) If I echo this I can see it all echo ${appArray[@]} > item1 -a -b item2 -...
3
votes
2answers
204 views

How do I remove all but the file name (with no extension) from a full file path? [duplicate]

I am presently writing a Bash function to convert all the man pages listed by equery files <PACKAGE> | grep /usr/share/man/man (if you are unfamiliar equery is a tool used on Gentoo-based ...
1
vote
3answers
124 views

Bash (Git) - Functions, Alias, and SH script files

I have gotten quite prolific with the use of the aliases, especially with all the different git commands and their order and interdependencies etc. So, I've created a few alias that run more complex ...
3
votes
4answers
329 views

How to create a function that can sort an array in bash?

I'm trying to figure out how to make a function that can take an array as a parameter and sort it. I think it is done with positional variables, but I'm not sure.
1
vote
1answer
31 views

Difference between writing `function Name { …; }`, `Name () { …; }` and `function Name () { …; }` in bash [duplicate]

You can write a bash functions several ways: function JoinStrings { ...; } Or function JoinStrings () { ...; } Or JoinStrings () { ...; } Is there any difference between these ...