Skip to main content

All Questions

Tagged with
4 votes
1 answer
162 views

Run in background avoiding any job control message from the shell [duplicate]

Lets define a shell function (here the shell is Bash) and test it $ s () { xterm -e sleep 5 & } $ s [1] 307926 $ [1]+ Done xterm -e sleep 5 $ With my specific meaning of ...
gboffi's user avatar
  • 1,336
3 votes
1 answer
248 views

How to overload / customize bash (or any other shell) commands handler?

When in bash some non existing command is run, corresponding error message appears: $ non-existent-command non-existent-command: command not found Is it possible to customize this behavior? I would ...
Anton Samokat's user avatar
1 vote
2 answers
119 views

Start interactive function definition from shell-script

Using zsh or bash, I want to run a script that may prompt the user for multiple commands and store them as a function, however I'm finding that eval "function $FNCNAME() {" or echo "...
Joakim Hagen's user avatar
0 votes
1 answer
163 views

How to create functions using for loops?

I'm trying to use a for loop to create functions for choosing passwords in my Arch install script (based on easy-arch) using the following code (which uses this se answer for repeating prompts and ...
321ytrewq's user avatar
5 votes
1 answer
2k views

zsh: pass variable by reference, and modify its value (like bash's local -n namerefs)?

Is it possible to pass a variable to a zsh function, and modify its value without using eval? I came across a bash way to do that: local -n: https://stackoverflow.com/a/50281697
codepoet's user avatar
  • 626
0 votes
1 answer
215 views

How to Control Number of Parameters Entered to Function

I am trying to make a simple menu-driven calculator script. I want there to be an error message displayed whenever the user does not enter the correct parameters when they call the add() or subtract() ...
hashslingingbasher's user avatar
2 votes
0 answers
753 views

Is valid use 'source' within a function?

Like an introduction: if secondary.sh has functionX(){ ... } and primary.sh has - source secondary.sh declared - and its own functions, therefore: # primary.sh content source secondary.sh ...
Manuel Jordan's user avatar
2 votes
0 answers
125 views

Why `declare -p VAR` returns "declare -- VAR" on an unset local variable but gives an error "bash: declare: A: not found" on an unset global variable?

I don't understand: $ declare -i VAR=0; \ > echo "$A"; \ > fun() { local -i VAR=1; echo {; echo "$VAR"; declare -p VAR; unset VAR; echo "$VAR"; declare -p VAR; echo ...
The Quark's user avatar
  • 270
0 votes
1 answer
105 views

Copy files from multiple directories and paste it into multiple directories

I have a directory " /data/archive In this directory there are 8 different subdirectories. eg : /data/archive/a /data/archive/b and so on Files under these subdirectories have date appended to ...
Aayush Jain's user avatar
0 votes
1 answer
2k views

How to call .bashrc function in script

~/.bashrc ---- example() { echo "example function" } If I use this in a shell script #!/bin/sh example I get command not found. I have tried #!/bin/sh source ~/.bashrc example but ...
mcp's user avatar
  • 777
1 vote
1 answer
3k views

Passing a variable from one function to another in bash script

Iam new to linux and trying to pass a variable from one function to another in a same bash script. Below is my code: #!/bin/bash -x FILES=$(mktemp) FILESIZE=$(mktemp) command_to_get_files(){ aws ...
clarie's user avatar
  • 95
2 votes
3 answers
364 views

Why does a file move/copy function only move one file at a time when using the “*” wildcard?

function mv1 { mv -n "$1" "targetdir" -v |wc -l ;} mv1 *.png It does only move the first .png file it finds, not all of them. How can I make the command apply to all files that match the wildcards?
neverMind9's user avatar
  • 1,710
1 vote
2 answers
1k views

Accessing function documentation

Is there a way to access docstrings in Bash? How does one include a docstring in a function's definition in Bash? More specifically how do I add and access docstrings to the following function? ...
alias's user avatar
  • 35
1 vote
2 answers
7k views

sudo without sudo, implying sudo in script

I made some scripts containing some functions which by design needs sudo permission. I have added those path in .bashrc for Linux and .bash_profile for MacOS so that it can be called from anywhere. ...
Rakib Fiha's user avatar
0 votes
1 answer
174 views

Can an array be the first argument to a function? [duplicate]

I have a function that one of the arguments is an string that has space separated words. E.g. "foo bar ccc" I think this kind of string can be treated as an "array" and loop over each word. My ...
Jim's user avatar
  • 1,459

15 30 50 per page