foo () {
echo $1 # $1 is the first argument
}
foo
# alternative way
function foo {
echo $1
}
foo
#!/bin/bash
function greet {
echo "Hi there!"
}
greet
#FIRST METHOD
Hello () {
echo 'Hello Wordl'
}
Hello
#SECOND METHOD
function Hello {
echo 'Hello Wordl'
}
Hello
#!/bin/bash
#Call a function without arguments
function quit {
exit
}
#Call a function with arguments
function e {
echo $1 #$1 will be set to the first argument given
}
function_name () {
<commands>
}
killport(){
sudo kill -9 $(sudo fuser -n tcp $1 2> /dev/null);
}
Now put this function in your bash configuration file, eg ~/.bashrc and then run:
source ~/.bashrc
print_something () {
echo Hello I am a function
}
#!/bin/bash
hello_world () {
echo 'hello, world'
}