Results 1 to 10 of 28
Where do I learn Bash Programming from ?
Any source where I can download source code or script to learn ?
I'm reading "Learning Bash" , but its not helping ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-13-2012 #1Just Joined!
- Join Date
- Nov 2012
- Posts
- 18
Bash Programming
Where do I learn Bash Programming from ?
Any source where I can download source code or script to learn ?
I'm reading "Learning Bash" , but its not helping me
- 11-13-2012 #2
Hi and welcome
Is this what you are reading?
Learning the bash Shell: Unix Shell Programming (In a Nutshell (O'Reilly)): Cameron Newham: 9780596009656: Amazon.com: Books
In what area or specific case do you need help?You must always face the curtain with a bow.
- 11-13-2012 #3Just Joined!
- Join Date
- Nov 2012
- Posts
- 18
Okay, I'm looking @ 1 file.
shell file
movielist.txtCode:#display main ticketing menu display_menu() { # Called by run_menu echo echo "-- Theatre Self-service Ticketing --" echo -n "1. " echo -e '\E[1;32;40mList all Movies and Show time\E[0m' echo -n "2. " echo -e '\E[1;32;40mDisplay theatre鈥檚 seat \E[0m' echo -n "q. " echo -e '\E[1;31;47mQuit\E[0m' echo -en "Enter your selection: " } # List out available movies list_movies() { # Called by run_menu old_IFS=$IFS IFS=$'\n' print_movie_header for LINE in `sed -e 's/Yes/Ticket Available/g' -e 's/No/SOLD OUT/g' movielist.txt` do print_movie $LINE done IFS=$old_IFS } # Output header for movie listing # Catered for both numbered and non-numbered list print_movie_header() { echo -e '\E[1;32;40m' if [ $# == "1" ];then echo -n " " fi echo -n -e 'Movie Title' set_colwidth 'Movie Title' 25 echo -n -e 'Show Time\t' if [ $# == "1" ];then echo -n -e "\t" fi echo -n 'Vacancy' echo -e '\E[0m' } # Set the width of column # $1 is the text in the column # and $2 is the intended column width set_colwidth() { STRING=$1 LENGTH=${#STRING} for (( i=$LENGTH; i<=$2; i++)) do echo -n " " done } # Output movie entry print_movie() { TIME=`echo $1 | cut -f1 -d ","` TITLE=`echo $1 | cut -f2 -d ","` AVAILABLE=`echo $1 | cut -f3 -d ","` echo -n -e $TITLE set_colwidth $TITLE 25 echo -n -e $TIME '\t' echo $AVAILABLE } # Hint2 # Get current seating arrangement of # selected movie from seating.txt movie_data() { COUNT=1 old_IFS=$IFS IFS=$'\n' for LINE in `cat seating.txt` do if test $1 -eq $COUNT then display_seats $LINE $2 fi THEATER[$COUNT]=$LINE let COUNT=COUNT+1 done IFS=$old_IFS } # Mark occupied seat with a X and # seats selected by user with a red X mark_seat() { # Called by display_seats if [ $(echo "$1" | grep -c "$2$3") -gt 0 ] then echo -n "X" set_colwidth "" 5 elif [ $(echo "$4" | grep -c "$2$3") -gt 0 ] then echo -en '\E[1;31mX\E[0m' set_colwidth "" 5 else set_colwidth "" 6 fi } # Print out theater's seating arrangement display_seats() { COL=5 ROW=4 echo echo "---------------------------------------" echo -e '\E[1;34;47m----------------SCREEN-----------------\E[0m' echo "---------------------------------------" for (( x=0; x<=$ROW; x++)) do echo -n "$x" | tr "0" " " for (( j=0; j<=$COL; j++)) do if [ $x == "0" ] then echo -n $j | tr "012345" " ABCDE" set_colwidth "" 5 else CURR_COL=$(echo $j | tr "12345" "ABCDE") if [ $j == "0" ] then set_colwidth "" 6 else mark_seat $1 $CURR_COL $x $2 fi fi done echo "" done echo "---------------------------------------" } # Select and book seat manually select_seat() { # Called by run_menu COUNT=0 echo echo "-- Select A Seat Manually --" echo old_IFS=$IFS IFS=$'\n' print_movie_header "numbered" for LINE in `sed -e 's/Yes/Ticket Available/g' -e 's/No/SOLD OUT/g' movielist.txt `;do let COUNT=COUNT+1 echo -n "$COUNT. " print_movie $LINE done IFS=$old_IFS echo # Select movie to book echo -en "Select Movie To Book (Enter 1 to ${COUNT}): " read NUM NUMERIC=0 while [ "$NUMERIC" != "1" ];do for (( x=$COUNT; x>=1; x--)) do if [ $NUM == "$x" ];then NUMERIC=1 fi done if [ "$NUMERIC" != "1" ];then echo -en "Invalid Movie Selected, Try Again (Enter 1 to ${COUNT}): " read NUM fi done movie_data $NUM echo old_IFS=$IFS IFS=$'\n' echo } # Main menu navigation run_menu() { i=-1 while [ "$i" != "q" ]; do display_menu read i i=`echo $i | tr '[A-Z]' '[a-z]'` case "$i" in "1") list_movies ;; "2") select_seat ;; "q") echo "GoodBye, Have A Nice Day" exit 0 ;; *) echo "Unrecognised Input." ;; esac done } #----------------------------------------------# # ---------PROGRAM SCRIPT START HERE---------- # #----------------------------------------------# if [ ! -f movielist.txt ]; then echo "Error: Movie list is not available" fi run_menu
seating.txtCode:1300 – 2Oct,The Social Network,No 1300 – 2Oct,The Town,Yes 1700 – 2Oct,Paranormal Activity 2,Yes 1900 – 2Oct,You Again,Yes 2100 – 2Oct,Kamui,Yes
Can anyone explain to me the shell ?Code:0;,A2,A3,A1,A7,A9 0;,E6,E7,E8 14;,A1,D4,C3,B3,A4,E4 15;,A1,D4,E2,C3,A2 15;,A1,B2,C3,D4,A4
How do you create extra table in the heading
Movie Title Time Slot Availability (how to include Book Now )
How do you also align the data to fit the header
- 11-14-2012 #4Just Joined!
- Join Date
- Nov 2012
- Posts
- 18
anyone or any book who can teach me how to use bash/
- 11-14-2012 #5Linux Newbie
- Join Date
- Nov 2012
- Posts
- 134
- 11-15-2012 #6Just Joined!
- Join Date
- Nov 2012
- Posts
- 18
Can anyone willing to teach me , online tutoring ?
- 11-20-2012 #7Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,700
i believe that is beyond the constraints of a forum. You've got read what you can, absorb it, and apply it to the code that you attempt. Follow tutorials and perform the examples they provide. You will get it, just stick with it.
For these types of formatting issues, you ought to use printf. It is a Bash shell built-in function, and possibly also a more capable binary (/bin/printf). Here's an example:How do you create extra table in the heading
How do you also align the data to fit the header
The "%s" is simply the string you are printing. The "%-8s" means to left justify text, to the 8th character. Similar with %-20s. You can also right justify, and a bunch of other stuff with printf.Code:#!/bin/bash menus=(colA colB colC colD) values=('foo' 'bar' 'really long value' 'meh') printf "%-8s" ${menus[0]} printf "%-8s" ${menus[1]} printf "%-20s" "${menus[2]}" printf "%s\n" ${menus[3]} printf "%-8s" ${values[0]} printf "%-8s" ${values[1]} printf "%-20s" "${values[2]}" printf "%s\n" ${values[3]}Last edited by atreyu; 11-20-2012 at 03:26 AM. Reason: typo
- 11-20-2012 #8Just Joined!
- Join Date
- Nov 2012
- Posts
- 18
Code:print_movie_header() { echo -e '\E[1;32;40m' #colour highlight if [ $# == "1" ];then echo -n " " fi echo -n -e 'Movie Title' #movie title appears with the length of 25 char set_colwidth 'Movie Title' 25 echo -n -e 'Show Time\t' if [ $# == "1" ];then echo -n -e "\t" fi echo -n 'Vacancy' #vacancy echo -e '\E[0m' #end of highlight } # Set the width of column # $1 is the text in the column # and $2 is the intended column width set_colwidth() { STRING=$1 LENGTH=${#STRING} for (( i=$LENGTH; i<=$2; i++)) #S2 refers to ??? Let us say I want more values do echo -n " " done } # Output movie entry print_movie() { TIME=`echo $1 | cut -f1 -d ","` TITLE=`echo $1 | cut -f2 -d ","` AVAILABLE=`echo $1 | cut -f3 -d ","` echo -n -e $TITLE set_colwidth $TITLE 25 echo -n -e $TIME '\t' echo $AVAILABLE }
Right now, it shows
Movie Title Timing Availability
Bla Bla -------------- 1500 ---------- YES / Sold Out #because of the sed function
It happens like that when I try to have 4 information under header
Header1 ------------Header2-----------Header3-----------Header4
Bla1------------- ---- Bla 2 ---------------Bla3
Bla4
- 11-20-2012 #9Just Joined!
- Join Date
- May 2012
- Posts
- 43
Just look where there's only something declared 3 times instead of 4.
See, you're only cutting 3 headings instead of 4.Code:print_movie() { TIME=`echo $1 | cut -f1 -d ","` TITLE=`echo $1 | cut -f2 -d ","` AVAILABLE=`echo $1 | cut -f3 -d ","` echo -n -e $TITLE set_colwidth $TITLE 25 echo -n -e $TIME '\t' echo $AVAILABLE }
- 11-20-2012 #10Just Joined!
- Join Date
- Nov 2012
- Posts
- 18


Reply With Quote

