The tag has no usage guidance.

learn more… | top users | synonyms

0
votes
2answers
114 views

Shell script using function () not finding command

I'm learning shell scripting and I'm studying how to use function in the shell script. The script is suppose to run as a basic math calculator with two defined numbers by the user. It's suppose to add,...
2
votes
1answer
40 views

Is there any danger to using an unset variable in a bash function definition?

Doing some code refactoring, and I realized I don't know if this matters at all: The function definition is going to be sourced from another file (a sort of library). The function uses certain ...
2
votes
3answers
151 views

Source only part of a script from another script?

This would probably never be the BEST approach to something, but I'm wondering if it's even possible. Something like: awk '/function_i_want_to_call/,/^$/{print}' script_containing_function | xargs ...
0
votes
1answer
15 views

Creating a function that reads off an input list of files

I am new to UNIX/Linux and am in the process of writing bioinformatics pipelines. These pipelines take in input files and pass them through multiple packages. Say there is a list of files that goes ...
6
votes
1answer
126 views

Function to simplify grep with an often used log

First off, sorry if this is a painfully newbish question! I'm trying make a function that simplifies grepping a log I have to work with on a regular basis. I'd like to use extended regexp with it ...
0
votes
2answers
1k views

Bash Scripting echo locally in a function

In bash scripts I try to keep my variables local to functions wherever I can and then pass what I need out of functions like bellow #!/bin/bash function FUNCTION() { local LOCAL="value" echo ...
1
vote
2answers
61 views

Cursor position in vi at opening of the file

vishex () { echo '#!/bin/bash' > $1; chmod +x $1; vi $1 } The goal of the above function is to have an alias for fast and comfortable creation of bash scripts. I would like that at ...
2
votes
3answers
350 views

Bash function with `getopts` only works the first time it's run

I defined the function f in Bash based on the example here (under "An option with an argument"): f () { while getopts ":a:" opt; do case $opt in a) echo "-a was triggered, ...
1
vote
1answer
270 views

bash: syntax error near unexpected token

I'm trying to create a bash alias alias backlight='__backlight () { echo "$@"; cd ~/Code/MSI-Backlight; sudo nodejs ~/Code/MSI-Backlight/msi-backlight.js "$@"; }', it works fine with no parameters but ...
0
votes
2answers
43 views

change permissions to a file and everything inside , recursively

So I want to create an alias called changeAllPermisions that accepts one parameter argument in such a way that when changeAllPermissions argument is called , both Group and Other do not have access to ...
0
votes
0answers
28 views

Lttng tracepoint(provider,tpname, arg)

I want to insert lttng - tracepoint("traceprovider_name"tracepoint_name" "$1"$2") statements with same tracepoint_name and traceprovider_name but with different arguments: for example: 1)How to ...
0
votes
1answer
135 views

Calling php function from /var/www/folder (as www-user), which is located in a file in /var (or any folder) (with root permissions?)

I wrote a script which "walks" through /var/www/xyz and scans folders and more. The folders are all 'user-bound', so the permissions for a single folder there are set to the specific user. Running ...
0
votes
2answers
162 views

How to increment local variable in Bash?

Data 1 \begin{document} 3 Code #!/bin/bash function getStart { local START="$(awk '/begin\{document\}/{ print NR; exit }' data.tex)" echo $START } START2=$(getStart) echo $...
0
votes
2answers
88 views

Returning local values from Bash variables?

I studied this article called Returning Values from Bash Functions. Data Lorem. \begin{document} hello \end{document} Case #1 which does not work Code #!/bin/bash function getStart { ...
3
votes
1answer
50 views

functions arguments

I am having trouble with what should be a simple bash script. I have a bash script that works perfectly: function convert_to () x_max=2038 y_max=1146 x_marg=100 y_marg=30 x_grid=150 y_grid=150 if (...
5
votes
4answers
612 views

How to use call-by-reference on an argument in a bash function

I am trying to pass a "var name" to a function, have the function transform the value the variable with such "var name" contains and then be able to reference the transformed object by its original "...
1
vote
2answers
117 views

Returning a variable from a function [closed]

I have the Linux script shown below. I can get it to return from the method decrypt nothing which I need to unzip a file. The method decrypt sends a string with the name of a zip file. Please give ...
2
votes
2answers
207 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 $*...
1
vote
2answers
598 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
4answers
116 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
127 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
153 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 '...
3
votes
1answer
259 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
159 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
300 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
178 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
145 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 --out-...
5
votes
2answers
215 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
751 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
51 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
81 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
275 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
174 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
253 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 ...
1
vote
1answer
107 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 ./...
1
vote
1answer
99 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
31 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
214 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 ...
3
votes
1answer
326 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
96 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
126 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
35 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
107 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 > /etc/...
1
vote
2answers
164 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
127 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
334 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 1....
3
votes
3answers
188 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 /some/...
2
votes
3answers
290 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
46 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
330 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 ...