Questions tagged [bash-function]

A sequence of bash commands that can be called with a function name.

A sequence of bash commands that can be called with a function name. Functions are defined like this:

function fname() {
  echo Hello world
}

Or:

fname() {
  echo Hello world
}

You can now call:

fname

The same with parameters:

function fname() {
  echo $1 $2
}

Call as:

fname Hello world
38 questions
0
votes
1 answer

Bash function not executing the input command

In a bash file s.sh, I have an Executor function to which I pass the commands to be executed. Whenever some command does not work as expected, this function outputs the command. Executor() { if ! $* then echo "$*" exit 2 …
Sashank
  • 590
  • 7
  • 22
0
votes
1 answer

obsolete function remains in bash enviroment

If I define a function in a bash script, e.g., envsetup.sh function blabla() { echo "blabla" } then i source it by . envsetup.sh There is blabla function in my environment to use. However, if I remove this function and source it again, the…
pepero
  • 7,095
  • 7
  • 41
  • 72
0
votes
1 answer

Escaping parameter to bash function

First I'll describe the problem. I often copy files from my linux desktop to my android tablet. For reasons I'd rather not go into, the easiest way I found to do this is by running sshDroid (a ssh server) on my tablet, and using scp from the shell…
Aydin Gerek
  • 272
  • 1
  • 11
0
votes
1 answer

alias to trigger script sh that needs to execute

Beginner here, Have been reading and trying lots of ideas just kind of frustrated now. learning about alias and bash functions It all begins because I am trying to learn swift came up with an error last week that put me in a tailspin for hours. But…
iSpeedyG
  • 1
  • 3
0
votes
1 answer

Bash: Formatting multi-line function results alongside each other

I have three functions that digest an access.log file on my server. hitsbyip() { cat $ACCESSLOG | awk '{ print $1 }' | uniq -c | sort -nk1 | uniq } hitsbyhour() { cat $ACCESSLOG | cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":00"}'…
Jeanmichel Cote
  • 531
  • 1
  • 5
  • 19
0
votes
2 answers

Why doe the shell script does not accept first argument

I am new to unix shell scripting. I am trying to execute sample function with arguments but the shell does not recognize the first argument as first but rather as second. #!/bin/bash func(){ echo "func" if [ -z $1 ] then echo "$1…
0
votes
1 answer

replaceInAll script working on cli but not as an .bashrc function

This .bashrc function is working on the command line, its a nice bash one line'er. but moving it into the bash profile and it stops working ? replaceInAll (){ find . -name "$1" -print | xargs sed -i 's/$2/$3/g' } what am i not getting wright…
dmc
  • 401
  • 4
  • 14
0
votes
1 answer

Bash's function will invoke command with quoted argument broken down?

Let's say I have a function in Bash: function ll { command ls -l $* } so it is to make ll works like ls -l. Most of the cases, it will work, but ls -l "ha ha" can work for the file with name ha ha, but ll "ha ha" will fail, because it is…
Jeremy L
  • 3,770
  • 6
  • 41
  • 62
1 2
3