alias l.='ls -d .* --color=tty'
alias ll='ls -l --color=tty'
alias ls='ls --color=tty'
alias vi='vim'
4.12.2. How Does It Work?
When the kernel receives a request to execute a file (and that file is executable), it uses
If the first two bytes of the file are #! , which counts as a magic number, the file is treated as a script: a pathname is read from the file starting at the third byte and continuing to the end of the first line. The shell or interpreter program identified by this pathname is executed, and the script name and all arguments are passed to the interpreter.
If a file has no magic number or shebang line, the kernel will attempt to execute it as though the value of the SHELL environment variable were given on the shebang line.
4.12.3. What About...
4.12.3.1. ...interacting with the user through the graphical user interface?
Other scripting languages such as Perl and Python can be used to construct full-scale GUI applications, but the
Here is the number-guessing script rewritten to use
#!/bin/bash
#
# number-guessing game - GUI version
#
# If the user entered an argument on the command
# line, use it as the upper limit of the number
# range
if [ '$#' -eq 1 ]
then
MAX=$1
else
MAX=100
fi
# Set up other variables
SECRET=$(( (RANDOM % MAX) + 1 )) # Random number 1-100
TRIES=0
GUESS=-1
# Display initial messages
zenity --info --text
'I have a secret number between 1 and $MAX. Try and guess it!'
--title 'Guess-It'
# Loop until the user guesses the right number
while [ '$GUESS' -ne '$SECRET' ]
do
# Prompt the user and get her input
((TRIES++))
GUESS=$(zenity --entry --text 'Enter guess #$TRIES:' --title 'Guess...')
# Display low/high messages
if [ '$GUESS' -lt '$SECRET' ]
then
zenity --info --text 'Too low!'
fi
if [ '$GUESS' -gt '$SECRET' ]
then
zenity --info --text 'Too high!'
fi
done
# Display final messages
zenity --info --text 'You guessed it! It took you $TRIES tries.' --title 'Congratulations!'
Figure 4-16 shows the
Figure 4-16. zenity dialogs
4.12.4. Where Can I Learn More?