shebang ('#!/bin/bash')
\n ('\n')
\n ('\n')
Comment ('# Simple line count example, using bash')
\n ('\n')
Comment ('#')
\n ('\n')
Comment ('# Bash tutorial: http://linuxconfig.org/Bash_scripting_Tutorial#8-2-read-file-into-bash-array')
\n ('\n')
Comment ('# My scripting link: http://www.macs.hw.ac.uk/~hwloidl/docs/index.html#scripting')
\n ('\n')
Comment ('#')
\n ('\n')
Comment ('# Usage: ./line_count.sh file')
\n ('\n')
Comment ('# -----------------------------------------------------------------------------')
\n ('\n')
\n ('\n')
word ('function')
= ('=')
OPEN_QUOTE ('"')
var ('$1')
CLOSE_QUOTE ('"')
\n ('\n')
\n ('\n')
Comment ('# Link filedescriptor 10 with stdin')
\n ('\n')
word ('exec')
WHITE_SPACE (' ')
int ('10')
<& ('<&')
int ('0')
\n ('\n')
Comment ('# stdin replaced with a file supplied as a first argument')
\n ('\n')
word ('exec')
WHITE_SPACE (' ')
< ('<')
WHITE_SPACE (' ')
var ('$1')
\n ('\n')
Comment ('# remember the name of the input file')
\n ('\n')
word ('in')
= ('=')
var ('$1')
\n ('\n')
\n ('\n')
Comment ('# init')
\n ('\n')
word ('file')
= ('=')
OPEN_QUOTE ('"')
STRING_CONTENT ('current_line.txt')
CLOSE_QUOTE ('"')
\n ('\n')
let ('let')
WHITE_SPACE (' ')
word ('count')
= ('=')
int ('0')
\n ('\n')
\n ('\n')
Comment ('# this while loop iterates over all lines of the file')
\n ('\n')
while ('while')
WHITE_SPACE (' ')
word ('read')
WHITE_SPACE (' ')
word ('LINE')
\n ('\n')
do ('do')
\n ('\n')
WHITE_SPACE ('    ')
Comment ('# increase line counter')
\n ('\n')
WHITE_SPACE ('    ')
( ('(')
( ('(')
word ('count')
++ ('++')
) (')')
) (')')
\n ('\n')
WHITE_SPACE ('    ')
Comment ('# write current line to a tmp file with name $file (not needed for counting)')
\n ('\n')
WHITE_SPACE ('    ')
word ('echo')
WHITE_SPACE (' ')
var ('$LINE')
WHITE_SPACE (' ')
> ('>')
WHITE_SPACE (' ')
var ('$file')
\n ('\n')
WHITE_SPACE ('    ')
Comment ('# this checks the return code of echo (not needed for writing; just for demo)')
\n ('\n')
WHITE_SPACE ('    ')
if ('if')
WHITE_SPACE (' ')
[ ('[')
WHITE_SPACE (' ')
var ('$?')
WHITE_SPACE (' ')
word ('-ne')
WHITE_SPACE (' ')
int ('0')
WHITE_SPACE (' ')
] (']')
\n ('\n')
WHITE_SPACE ('     ')
then ('then')
WHITE_SPACE (' ')
word ('echo')
WHITE_SPACE (' ')
OPEN_QUOTE ('"')
STRING_CONTENT ('Error in writing to file ')
$ ('$')
{ ('{')
word ('file')
} ('}')
STRING_CONTENT ('; check its permissions!')
CLOSE_QUOTE ('"')
\n ('\n')
WHITE_SPACE ('    ')
fi ('fi')
\n ('\n')
done ('done')
\n ('\n')
\n ('\n')
word ('echo')
WHITE_SPACE (' ')
OPEN_QUOTE ('"')
STRING_CONTENT ('Number of lines: ')
var ('$count')
CLOSE_QUOTE ('"')
\n ('\n')
word ('echo')
WHITE_SPACE (' ')
OPEN_QUOTE ('"')
STRING_CONTENT ('The last line of the file is: ')
OPEN_BACKQUOTE ('`')
word ('cat')
WHITE_SPACE (' ')
$ ('$')
{ ('{')
word ('file')
} ('}')
CLOSE_BACKQUOTE ('`')
CLOSE_QUOTE ('"')
\n ('\n')
\n ('\n')
Comment ('# Note: You can achieve the same by just using the tool wc like this')
\n ('\n')
word ('echo')
WHITE_SPACE (' ')
OPEN_QUOTE ('"')
STRING_CONTENT ('Expected number of lines: ')
OPEN_BACKQUOTE ('`')
word ('wc')
WHITE_SPACE (' ')
word ('-l')
WHITE_SPACE (' ')
var ('$in')
CLOSE_BACKQUOTE ('`')
CLOSE_QUOTE ('"')
\n ('\n')
\n ('\n')
Comment ('# restore stdin from filedescriptor 10')
\n ('\n')
Comment ('# and close filedescriptor 10')
\n ('\n')
word ('exec')
WHITE_SPACE (' ')
int ('0')
<& ('<&')
int ('10')
WHITE_SPACE (' ')
int ('10')
<& ('<&')
word ('-')
\n ('\n')
\n ('\n')
\n ('\n')
word ('name')
= ('=')
RAW_STRING (''name'')
\n ('\n')
\n ('\n')
$ ('$')
{ ('{')
word ('asdasd')
param_separator ('#')
word ('assdf')
} ('}')
\n ('\n')
$ ('$')
{ ('{')
word ('asdasd')
param_separator ('#')
word ('assdf')
} ('}')