The tag has no wiki summary.

learn more… | top users | synonyms

1
vote
2answers
47 views

Returning an variable from a function

I have the Linux script from bellow. I can get to return from the method decrypt nothing in order to unzip a file. The method decrypt sends a string with the name of a zip file. Please give some ...
2
votes
2answers
121 views

Execute only if it is a bash function

I'm looking for something similar to Bash's built-in command that will only run something if it is a function. So currently I have an insecure way of doing: # Go through arguments in order for i in ...
2
votes
2answers
82 views

How to call in a kernel level function in user space [closed]

I've developed some helper functions in the kernel. They're called by other functions in the kernel. Currently, they make my custom kernel panic :( For now (i.e. debugging), I made them as a passive ...
1
vote
0answers
27 views

Can't get bare-bone simple bash function to work [closed]

I have some tmux scripts in a directory, and I'm trying to make a script to make it easier to call them. Function is below tms() { ~/linux/scripts/tmux-scripts/$1 } This is in my bashrc, I then ...
1
vote
4answers
72 views

Problem with entire function in a script

I want to detect online network/shell services in my Solaris. I write following script for this purpose: compare_ser() { if [ "$1" != "" ]; then echo "True" >> Solaris.txt fi } export -f ...
1
vote
1answer
57 views

sh - Using Arguments in .profile functions

I want to use an argument in the function I created in my .profile file. I want to ask for input if no argument is given, otherwise set a variable to $1. When I check $1 to see if it is empty, I ...
1
vote
3answers
73 views

Using a function defined in a parent script

I wrote the following script in the test.sh: #!/bin/sh compare() { if [ $1 != root ]; then echo "Fail" >> CAT1.txt fi } awk -F: '$4 == 0' /etc/passwd | cut -d: f1 | xargs -n1 -i bash -c ...
1
vote
1answer
47 views

What is the difference between `autoload` and `autoload -U` in Zsh?

What is the difference between autoload -U and plain autoload? For instance, here it is recommended to run: autoload -U run-help autoload run-help-git autoload run-help-svn autoload run-help-svk ...
1
vote
2answers
55 views

Exporting a function from .profile/.bashrc

What am I doing wrong...? It's fine if I do this on the command line and then call it but not when I load it from .profile. Linux Mint Qiana, Bash 4.*, if it matters. function android() { command ...
2
votes
4answers
221 views

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
102 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
60 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
85 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
286 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
37 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
50 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
93 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
159 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
123 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
60 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
35 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
95 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
158 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
54 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
114 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
27 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
61 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
83 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
66 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
102 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
110 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
284 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
132 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
109 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
81 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
28 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
29 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
707 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
89 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
171 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
986 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
1k 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 ...
2
votes
1answer
80 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
215 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
107 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
432 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
100 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; ...