The tag has no wiki summary.

learn more… | top users | synonyms

1
vote
1answer
21 views

Function tracing per thread

I have a complex multi threaded application running on a Cent OS 5.8 the application is coded using C and C++ I am searching for a FUNCTION TRACING tool which can help me do the following Trace all ...
0
votes
1answer
22 views

Aliasing a command with parameter supplied to another command

Namely: I want to alias tail -f to less +F but let tail with any other parameter supplied work the same way as before.
2
votes
3answers
60 views

What happens if I pass too few parameters to a shell function?

I would like to ask about passing parameters into functions. I tried this: function_name $var1 $var2 but usually (sometimes it printed error) it didn't make any difference whether I passed them or ...
2
votes
1answer
101 views

grom() keyword in bash throws unexpected '(' token

I'm not entirely sure why I'm getting the error in my .bash_profile syntax error near unexpected token `(' when I use the keyword grom() for my function. I wanted to create a bash function that ...
0
votes
2answers
41 views

Its possible use special characters in a shell function name?

I have to create the function in shell script, that function name must contain the special characters. like >() { echo $1 $2 } Here my function name is >, If its ...
1
vote
3answers
105 views

What is the reason for having numbers within the brackets of a function ? [duplicate]

I have seen on many occasions a name of a function (frankly speaking I just call it function because of it typical appearance, they are though sometimes named commands or system calls but I do not ...
1
vote
1answer
22 views

Sort packages by size one-liner as function

While surfing web I've discovered nice one-liner that suits my needs well expac -s "%-30n %m" | sort -hk 2 | awk '{print $1, $2/1024/1024}' | column -t| However all the functional needed I got used ...
1
vote
0answers
6 views

execle function prototype [migrated]

I have recently been studying Unix system programming. I came across this in the man page of exec, int execle(const char *path, const char *arg,..., char * const envp[]); How does this function ...
0
votes
2answers
40 views

Bash function for piping data into protected file [duplicate]

I wanted to create a .bashrc function that would simplify passing data to a write-protected file. function pipe { sudo bash -c "$1" } Unfortunately the command pipe echo something > ...
1
vote
2answers
51 views

Bash: How to create an alias in .bashrc for awk with parameters

I'm trying to add an alias in .bashrc file as follows: ... alias cutf="_cutf" ... _cutf() { awk 'NR >= $2 && NR <= $3 { print }' < $1 } (The function's goal is to show the ...
1
vote
1answer
52 views

A basic function that doesn't work [duplicate]

I've tried several modifications to see why it's not working, but I can't find the answer. Here is my code, this is in french but this is just a normal fonction that ask to the user if he's ready to ...
2
votes
2answers
65 views

Bash command: is it possible to pass an argument before a custom command (function) or it must be only after:

I am wondering if it is possible to pass an argument to a custom command before the command? Let say I have custom command ping and I would like to pass the IP address before command: instead ping ...
3
votes
3answers
79 views

Write bash function which operates on list of filenames

I want to define the function cpfromserver in bash so that when I run $ cpfromserver xxx yyy zzz the result is the same as if I had typed $ scp user@remote.server:"/some/location/xxx/xxx.txt ...
2
votes
3answers
277 views

How can I pass on parameters 4..99 to another function

I'm calling a function and I want to pass up to 100 paramters onto another function. I do not want to pass on the first 3 params, I start with param4 being the first param for the other program. I ...
0
votes
0answers
30 views

Pass a function arguments?

How would you make a function that gets arguments? function arg_example { arg "c" # This is imaginary but it would return 'true' if it found the argument -c. did_find_arg=$? # Get the ...
3
votes
2answers
76 views

Why alias inside function does not work?

See the code below: a()(alias x=echo\ hi;type x;alias;x);a I have an alias inside a function, I do not want to change the external environment (that is why I am using () instead of {}), even the ...
2
votes
3answers
98 views

Is it possible to add a function within a function?

function update_profile { echo "1. Update Name" echo "2. Update Age" echo "3. Update Gender" echo "Enter option: " read option case $option in 1) update_name ;; ...
1
vote
1answer
52 views

Why doesn't my function work with spaces? (cd, dirname) [duplicate]

I have had this function I use it very often and it works fine. Here it is: cdx () { cd `dirname $1` ; } However, this does not work with spaces. When I use it like this for example cdx ...
0
votes
0answers
27 views

Broken mkdir command [duplicate]

I made an alias in my .bash_profile file with the same name as mkdir. It looked like this. alias mkdir='function _blah(){ mkdir "$1"; cd "$1" };_blah' After removing it, i notice that mkdir still ...
0
votes
1answer
20 views

Why urxvtc doesn't accetp zsh functions when called with a “-c” argument?

In order to launch a new terminal and run a zsh function on it, I am trying to run the following command from within an urxvtc terminal (the urxvtd is running as a systemd service) urxvtc -e zsh ...
3
votes
4answers
320 views

seek function in unix

I try to understand the seek(2) function from Unix version 6. This example: seek(0,0,2) So the first argument is the file descriptor. And 0 would be the standard input. The second argument is the ...
0
votes
1answer
50 views

Ugly bash function to send commands and “say” anything in screen over ssh. Is there a better way?

I’m working on a function this works but it is ugly. One thing that could be changed is being able to know the name of the screen. Using screen -dms minecraft java ….jar now starts a screen session ...
1
vote
4answers
113 views

Executing a command within `if` statement and on success perform further steps

I was trying to execute a program which will create a directory on the basis of a complete path provided to it from the prompt and, if the directory already exists it will return an error (for ...
3
votes
2answers
358 views

forward function and variables into sudo su - <user> <<EOF

I have declared functions and variables in bash/ksh and I need to forward them into sudo su - {user} << EOF: #!/bin/bash log_f() { echo "LOG line: $@" } extVAR="yourName" sudo su - ...
1
vote
3answers
525 views

What return/exit values can I use in bash functions/scripts?

I want to know what return values we can use that will not be mistaken by for ex. SIGINT? ex.: $sleep 10 $#hit ctrl+c $echo $? 130 so I know I must not use anything like return 130 or exit 130 so ...
1
vote
1answer
62 views

How do I define alias with variables which can be changed at runtime?

This is probably a very easy to answer question, but I could not find any questions already asking this due to different wording when writing titles. Running help alias on my bash prompt returns only ...
6
votes
1answer
189 views

Function that calls another function with list of arguments doesn't work

In my .bash_aliases I have defined a function that I use from the command line like this: search -n .cs -n .cshtml -n .html SomeTextIWantToSearchFor /c/code/website/ /c/stuff/something/whatever/ ...
2
votes
1answer
80 views

How to print the code of a shell function in terminal?

I am using zsh and I have defined few utility shell function in some shell scripts, few of them called from ~/.zshrc, so let's assume that the we don't know the location of these functions. One ...
2
votes
1answer
239 views

set -xv behavior in ksh vs bash

Normally I like to have all of the debug output of a script go to a file, so I will have something like: exec 2> somefile set -xv This work very will in bash, but I have noticed in ksh it ...
1
vote
0answers
86 views

export -f in .bashrc after upgrade to bash 4.3.30 kills builtins?

I recently upgraded my bash (Mac OS X 10.6.8) from 3.2.48(1) to 4.3.30(1) via macports, and while the install seems to have gone smoothly, the two spots in my ~/.bashrc where I had export -f myfunc; ...
1
vote
1answer
664 views

How to use defined function with xargs

This is my code #!/bin/bash showword() { echo $1 } echo This is a sample message | xargs -d' ' -t -n1 -P2 showword So I have a function showword which echoes whatever string you pass as a ...
8
votes
1answer
311 views

Why does bash even parse/run stuff put in the environment variable?

The shellshock bug in bash works by way of environment variables. Honestly I was suprised by the fact that there is such a feature like: "passing on of function definitions via env vars" Therefore ...
1
vote
1answer
728 views

/bin/sh: error importing function definition for `some-function'

I encountered this error when updating bash for the CVE-2014-6271 security issue: # yum update bash Running transaction (shutdown inhibited) Updating : bash-4.2.47-4.fc20.x86_64 /bin/sh: error ...
5
votes
1answer
493 views

How does VARIABLE=() { function definition } work in bash

I have seen something like this in my bash ENV: module=() { eval `/usr/bin/modulecmd bash $*` } How does this construct work? What is it called? I'm not asking about modulecmd, I am asking about ...
2
votes
1answer
108 views

Killing multiple instances of the script from the script itself

I've couple instances of script.sh running in parallel, doing the same thing, running in background. I'm trying to use a function to kill all the current running scripts when executed. So, for ...
4
votes
1answer
79 views

Calling `source` from bash function

I'm trying to source a file whose name is passed from stdin. My plan is to create a function like this: mySource() { # get stdin and pass it as an argument to `source` source $(cat) } to be ...
3
votes
0answers
111 views

Errtrace and local

I am using the following script: #!/bin/bash -Eu trap 'echo Hi' ERR exit_failure() { echo "Hello, World!" return 1 } sub_failure() { res=$(exit_failure) } sub_failure It results in the ...
2
votes
2answers
71 views

Call the script after disconnecting from server

I have a script I made for work that will call a function that takes an argument. I use the arguments to ssh into our servers. My question is: Is there a way to call the method so that if/when I get ...
2
votes
1answer
247 views

How can I get this script file's functions to load without having to source it every time? “command not found” (Bash/scripting basics)

How can I get this script file's functions to load without having to source it every time? I created a file foo with script functions I'd like to run. It's in /usr/bin, which is in the PATH. File ...
2
votes
2answers
599 views

How to force watch to run under bash

The problem is that when watch is executed it runs sh and I get this error: sh: 1: func1: not found here is the code: #!/bin/bash func1(){ echo $1 } export -f func1 watch func1
6
votes
1answer
255 views

BASH return to main function

I have a BASH script that calls a function, which calls other functions: #!/bin/bash function foo { function bar { # do something } bar } foo How can I return from bar ...
0
votes
2answers
2k views

Exit the bash function, not the terminal

I have a bash script as below which installs zookeeper but only if not installed already. ##zookeper installZook(){ ZOOK_VERSION="3.4.5" ZOOK_TOOL="zookeeper-${ZOOK_VERSION}" ...
5
votes
2answers
97 views

Command re-assigned

I found a Bash script snippet earlier with which to echo a string to stderr: echoerr() { echo "$@" 1>&2; } echoerr hello world This remained in my clipboard, and when I wanted to edit a file ...
2
votes
1answer
350 views

Value assigned inside a function variable is alway empty

I have a following simple script. In this script, I am assigning value to a global variable inside a function. I can clearly see that the value being assigned to the variable via debug statement. ...
1
vote
1answer
64 views

Bash array declared in a function is not available outside the function

on bash (v4.3.11) terminal type this: function FUNCtst() { declare -A astr; astr=([a]="1k" [b]="2k" ); declare -p astr; };FUNCtst;declare -p astr (same thing below, just to be easier to read here) ...
10
votes
2answers
921 views

How to document my custom bash functions and aliases?

Problem: I have multiple bash functions and aliases. I can't remember all of them off the top of my head, so I usually end up opening my .bash_functions and .bash_aliases files to find what I need. ...
1
vote
4answers
2k views

What does “while test $# -gt 0” do?

I'm trying to create a function and believe I found a good working example but I don't understand all the logic behind it. More specifically, on the "while" line, could someone explain what test is ...
3
votes
3answers
535 views

How to call a shell function

How can I use the integer value returned by a function in shell script that takes some arguments as input? I am using the following code: fun() { echo "hello ${1}" return 1 } a= fun 2 echo ...
0
votes
1answer
162 views

apply bash function to parent scope

I can to define function in bash and use it: foo() { echo $1; } foo test But if I want to collect my functions in one bash script all its unavailable: init.bash #!/bin/bash foo() { echo $1; } ...
7
votes
3answers
524 views

Bash Function Decorator

In python we can decorate functions with code that is automatically applied and executed against functions. Is there any similar feature in bash? In the script I'm currently working on, I have some ...