This link has been bookmarked by 282 people . It was first bookmarked on 20 Nov 2007, by Andrés David Aparicio Alonso.
-
14 Aug 14
-
14 Jun 13
-
28 Sep 11
-
27 Sep 11
-
François Georgy#!/bin/bash
#Declare array
declare -a ARRAY
#Open file for reading to array
exec 10
let count=0
while read LINE <? do
ARRAY[$count]=$LINE
((count++))
done
echo Number of elements: ${#ARRAY[@]}
# echo array's content
echo ${ARRAY[@]}
# close file
exec 1 -
29 Aug 11
-
29 Jun 11
-
11 May 11
-
This bash script tutorial assumes no previous knowledge of bash scripting.As you will soon discover in this quick comprehensive bash scripting guide, learning the bash shell scripting is very easy task.
Lets begin this bash scripting tutorial with a simple "Hello World" script. Let's start with Learning the bash Shell: Unix Shell Programming
-
-
18 Apr 11
-
14 Apr 11
-
28 Mar 11
-
20 Mar 11
-
08 Mar 11
-
05 Mar 11
-
16 Feb 11
-
11 Feb 11
-
10 Feb 11
-
07 Feb 11
-
27 Jan 11
-
26 Jan 11
-
05 Jan 11
-
11 Dec 10
-
10 Dec 10
-
08 Dec 10
-
Linux from Scratch
-
05 Dec 10
-
04 Dec 10
-
02 Dec 10
-
25 Nov 10
-
19 Nov 10
-
18 Nov 10
-
10 Nov 10
-
22 Oct 10
-
05 Oct 10
-
29 Sep 10
-
28 Sep 10
-
30 Aug 10
-
26 Aug 10
-
25 Aug 10
-
20 Aug 10
-
Bash File Testing
-
-f filename Check for regular file existence not a directory
-
-
16 Aug 10
-
$ chmod +x hello_world.sh
-
./hello_world.sh
-
#!/bin/bash
echo -e "Hi, please type the word: \c "
read word
echo "The word you entered is: $word"
echo -e "Can you please enter two words? "
read word1 word2
echo "Here is your input: \"$word1\" \"$word2\""
echo -e "How do you feel about bash scripting? "
# read command now stores a reply into the default build-in variable $REPLY
read
echo "You said $REPLY, I'm glad to hear that! "
echo -e "What are your favorite colours ? "
# -a makes read command to read into an array
read -a colours
echo "My favorite colours are also ${colours[0]}, ${colours[1]} and ${colours[2]}:-)" -
Bash quotes and quotations
-
Escaping will suppress a special meaning of meta characters and therefore meta characters will be read by bash literally. To do this we need to use backslash "\" character
-
Single quotes in bash will suppress special meaning of every meta characters.
-
It is not possible to use another single quote within two single quotes
-
Double quotes in bash will suppress special meaning of every meta characters except "$", "\" and "`".
-
The syntax fo ansi-c bash quoting is: $'' . Here is an example:
-
18. Redirections
-
by default stdout is automatically redirected to screen.
-
n this case the output of a command will be written to the same descriptor as a stderr
-
-
15 Aug 10
-
05 Aug 10
-
24 Jul 10
-
21 Jul 10
-
15 Jul 10
-
09 Jul 10
-
06 Jul 10
-
25 Jun 10
-
23 Jun 10
-
22 Jun 10
-
21 Jun 10
-
#!/bin/bash
STRING="HELLO WORLD!!!"
echo $STRING -
#!/bin/bash
# Declare variable choice and assign value 4
choice=4
# Print to stdout
echo "1. Bash"
echo "2. Scripting"
echo "3. Tutorial"
echo -n "Please choose a word [1,2 or 3]? "
# Loop while the variable choice is equal 4
# bash while loop
while [ $choice -eq 4 ]; do
# read user input
read choice
# bash nested if/else
if [ $choice -eq 1 ] ; then
echo "You have chosen word: Bash"
else
if [ $choice -eq 2 ] ; then
echo "You have chosen word: Scripting"
else
if [ $choice -eq 3 ] ; then
echo "You have chosen word: Tutorial"
else
echo "Please make a choice between 1-3 !"
echo "1. Bash"
echo "2. Scripting"
echo "3. Tutorial"
echo -n "Please choose a word [1,2 or 3]? "
choice=4
fi
fi
fi
done
-
-
18 Jun 10
-
09 Jun 10
-
02 Jun 10
-
directory="./BashScripting"
-
-
26 May 10
-
20 May 10
-
18 May 10
-
27 Apr 10
-
23 Apr 10
-
15 Apr 10
-
This bash script tutorial assumes no previous knowledge of bash scripting.As you will soon discover in this quick comprehensive bash scripting guide, learning the bash shell scripting is very easy task. Lets begin this bash scripting tutorial with a simple "Hello World" script. Let's start with Learning the bash Shell: Unix Shell Programming
-
-
13 Apr 10
-
06 Apr 10
-
26 Mar 10
-
20 Mar 10
-
19 Mar 10
-
18 Mar 10
-
14 Mar 10
-
04 Mar 10
-
01 Mar 10
-
12 Feb 10
-
01 Feb 10
-
25 Jan 10
-
18 Jan 10
-
16 Jan 10
-
15 Jan 10
-
18.8. stderr and stdout to file
grep -r hda6 * . &> stderr_and_stdout.txt
-
-
07 Jan 10
-
11 Dec 09
-
08 Dec 09
-
05 Dec 09
controlc deThis bash script tutorial assumes no previous knowledge of bash scripting.As you will soon discover in this quick comprehensive bash scripting guide, learning the bash shell scripting is very easy task. Lets begin this bash scripting tutorial with a simpl
-
26 Nov 09
-
24 Nov 09
-
22 Nov 09
-
18 Nov 09
-
14 Nov 09
-
12 Nov 09
-
04 Nov 09
-
18 Oct 09
-
This bash script tutorial assumes no previous knowledge of bash scripting.As you will soon discover in this quick comprehensive bash scripting guide, learning the bash shell scripting is very easy task. Lets begin this bash scripting tutorial with a simple "Hello World" script. Let's start with Learning the bash Shell: Unix Shell Programming
-
-
17 Oct 09
-
14 Oct 09
-
13 Oct 09
-
07 Oct 09
-
29 Sep 09
-
26 Sep 09
-
25 Aug 09
-
11 Jul 09
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.