2005-09-20 21:31:55 +08:00
|
|
|
#
|
2010-11-23 23:05:21 +08:00
|
|
|
#Test aliases, loops, conditionals and some basic elements
|
2005-09-20 21:31:55 +08:00
|
|
|
#
|
|
|
|
|
|
|
|
for i in 1 2 #Comment on same line as command
|
2010-09-18 10:18:26 +08:00
|
|
|
#Comment inside loop
|
2005-09-20 21:31:55 +08:00
|
|
|
for j in a b
|
|
|
|
#Double loop
|
|
|
|
echo $i$j
|
|
|
|
end;
|
|
|
|
end
|
|
|
|
|
2012-11-21 05:52:53 +08:00
|
|
|
# Bracket expansion
|
|
|
|
echo x-{1}
|
|
|
|
echo x-{1,2}
|
|
|
|
echo foo-{1,2{3,4}}
|
|
|
|
|
2012-11-22 17:09:07 +08:00
|
|
|
# Escpaed newlines
|
|
|
|
echo foo\ bar
|
|
|
|
echo foo\
|
|
|
|
bar
|
|
|
|
echo "foo\
|
|
|
|
bar"
|
|
|
|
echo 'foo\
|
|
|
|
bar'
|
|
|
|
|
2012-11-24 04:03:36 +08:00
|
|
|
for i in \
|
|
|
|
a b c
|
|
|
|
echo $i
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2005-09-20 21:31:55 +08:00
|
|
|
# Simple alias tests
|
|
|
|
|
2010-09-18 10:18:26 +08:00
|
|
|
function foo
|
2005-09-20 21:31:55 +08:00
|
|
|
echo >foo.txt $argv
|
|
|
|
end
|
|
|
|
|
|
|
|
foo hello
|
|
|
|
|
|
|
|
cat foo.txt |read foo
|
|
|
|
|
|
|
|
if test $foo = hello;
|
|
|
|
echo Test 2 pass
|
|
|
|
else
|
|
|
|
echo Test 2 fail
|
|
|
|
end
|
|
|
|
|
2010-09-18 10:18:26 +08:00
|
|
|
function foo
|
2005-09-20 21:31:55 +08:00
|
|
|
printf 'Test %s' $1; echo ' pass'
|
|
|
|
end
|
|
|
|
|
2010-09-18 10:18:26 +08:00
|
|
|
foo 3
|
2005-09-20 21:31:55 +08:00
|
|
|
|
|
|
|
for i in Test for continue break and switch builtins problems;
|
|
|
|
switch $i
|
|
|
|
case Test
|
2010-09-18 10:18:26 +08:00
|
|
|
printf "%s " $i
|
2005-09-20 21:31:55 +08:00
|
|
|
case "f??"
|
|
|
|
printf "%s " 3
|
|
|
|
case "c*"
|
|
|
|
echo pass
|
|
|
|
case break
|
|
|
|
continue
|
|
|
|
echo fail
|
|
|
|
case and
|
|
|
|
break
|
|
|
|
echo fail
|
|
|
|
case "*"
|
|
|
|
echo fail
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-11-23 23:05:21 +08:00
|
|
|
set -l sta
|
|
|
|
if eval true
|
|
|
|
if eval false
|
|
|
|
set sta fail
|
|
|
|
else
|
|
|
|
set sta pass
|
|
|
|
end
|
|
|
|
else
|
|
|
|
set sta fail
|
|
|
|
end
|
|
|
|
echo Test 4 $sta
|
2010-11-24 00:35:56 +08:00
|
|
|
|
|
|
|
function test_builtin_status
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
test_builtin_status
|
|
|
|
if [ $status -eq 1 ]
|
|
|
|
set sta pass
|
|
|
|
else
|
|
|
|
set sta fail
|
|
|
|
end
|
|
|
|
echo Test 5 $sta
|
2012-10-17 17:56:03 +08:00
|
|
|
|
|
|
|
# echo tests
|
|
|
|
|
|
|
|
echo 'abc\ndef'
|
|
|
|
echo -e 'abc\ndef'
|
|
|
|
echo -e 'abc\zdef'
|
|
|
|
echo -e 'abc\41def'
|
|
|
|
echo -e 'abc\041def'
|
|
|
|
echo -e 'abc\121def'
|
|
|
|
echo -e 'abc\1212def'
|
2012-10-17 17:59:43 +08:00
|
|
|
echo -e 'abc\cdef' # won't output a newline!
|
|
|
|
echo ''
|
2012-10-17 17:56:03 +08:00
|
|
|
|
|
|
|
echo -e Catch your breath
|
|
|
|
|
|
|
|
echo -e 'abc\x21def'
|
|
|
|
echo -e 'abc\x211def'
|