RosettaCodeData/Task/Stack/UnixPipes/stack-1.unixpipes

12 lines
322 B
Plaintext

init() { if [ -e stack ]; then rm stack; fi } # force pop to blow up if empty
push() { echo $1 >> stack; }
pop() {
tail -1 stack;
x=`head -n -1 stack | wc -c`
if [ $x -eq '0' ]; then rm stack; else
truncate -s `head -n -1 stack | wc -c` stack
fi
}
empty() { head -n -1 stack |wc -l; }
stack_top() { tail -1 stack; }