The tag has no wiki summary.

learn more… | top users | synonyms

2
votes
3answers
124 views
+100

locate alias with find

On small systems where there is no locate installed, How would an alias look like that gets the same result as locate? I can imagine find can produce the same output so an alias could look like ...
3
votes
2answers
101 views

Whats going on in this function?

log () { A=$1 print "`date '+%m/%d/%y %H:%M:%S'`: $A" >> LOGFILE.txt print "$A" } This is how log function used in most of the shell scripts in our environment. and its been used in ...
3
votes
4answers
52 views

How can I make source-highlight colorize .dotfiles by default?

Normally when I cat a file like this it's hard to read without colorizing. I've managed to get cat to use source-highlight like this: cdc() { for fn in "$@"; do source-highlight ...
5
votes
2answers
72 views

Elegant way to prevent command substitution from removing trailing newline

I'm customizing my zsh PROMPT and calling a function that may or may not echo a string based on the state of an environment variable: function my_info { [[ -n "$ENV_VAR"]] && echo "Some ...
5
votes
2answers
227 views

Can you execute a Bash function with the `at` command?

I want to execute a Bash function at a scheduled time. I think the right tool for this is the at command. However, it doesn't seem to be working. function stupid () { date } export -f stupid ...
1
vote
1answer
34 views

Aliasing a command with special parameters [duplicate]

I would like to have an alias for the following code:- g++ *.cc -o * `pkg-config gtkmm-3.0 --cflags --libs`; but I want that when I enter the alias it should be followed by the file name *.cc and ...
1
vote
2answers
48 views

Accessing fish functions from perl

In bash I can do: foo() { echo bar; } export -f foo perl -e 'system "bash -c foo"' I can also access the function definition: perl -e 'print "foo".$ENV{"BASH_FUNC_foo%%"}' How do I do the same ...
3
votes
2answers
82 views

How to use a bash function like a regular command in a pipe chain?

I'm performing several commands on large files from within a bash script. In order to monitor the progress I use the pv command. An example command could look like this cat $IN_FILE | pv -w 20 -s ...
10
votes
1answer
156 views

Track certain parameters on some command

Let's say that I have a command git branch (always with a couple of words) for example. What I want is to keep track of when this command is executed with arguments. For example, if I execute the ...
4
votes
2answers
104 views

Checking if a command is a built-in in ksh

How can I check if a command is a built-in command for ksh? In tcsh you can use where; in zsh and bash you can use type -a; and in some modern versions of ksh you can use whence -av. What I want to ...
0
votes
1answer
52 views

What's the best way to make a bash function in a script as a parameter when running via command line?

I'm fairly new to bash scripting, and wondered what's the simplest way to make bash script functions in a script as the parameter when run via command line? Example usage: ./myscript function1 ...
0
votes
0answers
21 views

Automated function Logging tool

Is there a automated tool for logging function name , function entry and exit parameters per thread for complex multi threaded application.(C / C++)
1
vote
1answer
30 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 ...
0
votes
1answer
29 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
85 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
145 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
49 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
113 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
26 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 ...
0
votes
2answers
57 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
74 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
58 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
89 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
104 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
283 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
34 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
111 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
101 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
73 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
26 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
617 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
76 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
146 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
773 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
985 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
74 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
208 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/ ...
3
votes
1answer
100 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
377 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
94 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
1k 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
351 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
925 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
600 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
148 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
81 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
144 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
72 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
412 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 ...