2005-09-20 13:31:55 +00:00
|
|
|
|
#
|
2010-11-23 15:05:21 +00:00
|
|
|
|
#Test aliases, loops, conditionals and some basic elements
|
2005-09-20 13:31:55 +00:00
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
for i in 1 2 #Comment on same line as command
|
2010-09-18 02:18:26 +00:00
|
|
|
|
#Comment inside loop
|
2005-09-20 13:31:55 +00:00
|
|
|
|
for j in a b
|
|
|
|
|
#Double loop
|
|
|
|
|
echo $i$j
|
|
|
|
|
end;
|
|
|
|
|
end
|
|
|
|
|
|
2012-11-20 21:52:53 +00:00
|
|
|
|
# Bracket expansion
|
|
|
|
|
echo x-{1}
|
|
|
|
|
echo x-{1,2}
|
|
|
|
|
echo foo-{1,2{3,4}}
|
|
|
|
|
|
2014-01-13 10:49:41 +00:00
|
|
|
|
# Escaped newlines
|
2012-11-22 09:09:07 +00:00
|
|
|
|
echo foo\ bar
|
|
|
|
|
echo foo\
|
|
|
|
|
bar
|
|
|
|
|
echo "foo\
|
|
|
|
|
bar"
|
|
|
|
|
echo 'foo\
|
|
|
|
|
bar'
|
|
|
|
|
|
2012-11-23 20:03:36 +00:00
|
|
|
|
for i in \
|
|
|
|
|
a b c
|
|
|
|
|
echo $i
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2005-09-20 13:31:55 +00:00
|
|
|
|
# Simple alias tests
|
|
|
|
|
|
2010-09-18 02:18:26 +00:00
|
|
|
|
function foo
|
2005-09-20 13:31:55 +00: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 02:18:26 +00:00
|
|
|
|
function foo
|
2005-09-20 13:31:55 +00:00
|
|
|
|
printf 'Test %s' $1; echo ' pass'
|
|
|
|
|
end
|
|
|
|
|
|
2010-09-18 02:18:26 +00:00
|
|
|
|
foo 3
|
2005-09-20 13:31:55 +00:00
|
|
|
|
|
|
|
|
|
for i in Test for continue break and switch builtins problems;
|
|
|
|
|
switch $i
|
|
|
|
|
case Test
|
2010-09-18 02:18:26 +00:00
|
|
|
|
printf "%s " $i
|
2005-09-20 13:31:55 +00: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 15:05:21 +00: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-23 16:35:56 +00:00
|
|
|
|
|
2015-01-17 23:22:37 +00:00
|
|
|
|
# Ensure eval doesn't unnecessarily mess with the exit status
|
|
|
|
|
function empty_func ; end
|
|
|
|
|
false ; eval empty_func ; echo $status
|
|
|
|
|
true ; eval empty_func ; echo $status
|
|
|
|
|
|
2010-11-23 16:35:56 +00: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 09:56:03 +00:00
|
|
|
|
|
2013-08-18 23:55:01 +00:00
|
|
|
|
# Verify that we can turn stderr into stdout and then pipe it.
|
|
|
|
|
# Note that the order here seems unspecified - 'errput' appears before 'output', why?
|
|
|
|
|
echo Test redirections
|
|
|
|
|
begin ; echo output ; echo errput 1>&2 ; end 2>&1 | tee /tmp/tee_test.txt ; cat /tmp/tee_test.txt
|
|
|
|
|
|
2014-01-13 10:49:41 +00:00
|
|
|
|
# Verify that we can pipe something other than stdout
|
|
|
|
|
# The first line should be printed, since we output to stdout but pipe stderr to /dev/null
|
|
|
|
|
# The second line should not be printed, since we output to stderr and pipe it to /dev/null
|
|
|
|
|
begin ; echo is_stdout ; end 2>| cat > /dev/null
|
|
|
|
|
begin ; echo is_stderr 1>&2 ; end 2>| cat > /dev/null
|
|
|
|
|
|
2012-10-17 09:56:03 +00: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 09:59:43 +00:00
|
|
|
|
echo -e 'abc\cdef' # won't output a newline!
|
|
|
|
|
echo ''
|
2014-05-16 07:19:07 +00:00
|
|
|
|
echo -
|
2012-10-17 09:56:03 +00:00
|
|
|
|
|
2015-01-15 19:21:07 +00:00
|
|
|
|
echo -ne '\376' | xxd -p
|
|
|
|
|
|
2012-10-17 09:56:03 +00:00
|
|
|
|
echo -e Catch your breath
|
|
|
|
|
|
|
|
|
|
echo -e 'abc\x21def'
|
|
|
|
|
echo -e 'abc\x211def'
|
2014-02-12 09:39:06 +00:00
|
|
|
|
|
2015-01-04 22:18:06 +00:00
|
|
|
|
# Verify that pipes don’t conflict with fd redirections
|
|
|
|
|
# This code is very similar to eval. We go over a bunch of fads
|
|
|
|
|
# to make it likely that we will nominally conflict with a pipe
|
|
|
|
|
# fish is supposed to detect this case and dup the pipe to something else
|
|
|
|
|
echo "/bin/echo pipe 3 <&3 3<&-" | source 3<&0
|
|
|
|
|
echo "/bin/echo pipe 4 <&4 4<&-" | source 4<&0
|
|
|
|
|
echo "/bin/echo pipe 5 <&5 5<&-" | source 5<&0
|
|
|
|
|
echo "/bin/echo pipe 6 <&6 6<&-" | source 6<&0
|
|
|
|
|
echo "/bin/echo pipe 7 <&7 7<&-" | source 7<&0
|
|
|
|
|
echo "/bin/echo pipe 8 <&8 8<&-" | source 8<&0
|
|
|
|
|
echo "/bin/echo pipe 9 <&9 9<&-" | source 9<&0
|
|
|
|
|
echo "/bin/echo pipe 10 <&10 10<&-" | source 10<&0
|
|
|
|
|
echo "/bin/echo pipe 11 <&11 11<&-" | source 11<&0
|
|
|
|
|
echo "/bin/echo pipe 12 <&12 12<&-" | source 12<&0
|
|
|
|
|
|
|
|
|
|
|
2014-07-11 18:28:10 +00:00
|
|
|
|
# Make sure while loops don't run forever with no-exec (#1543)
|
|
|
|
|
echo "Checking for infinite loops in no-execute"
|
|
|
|
|
echo "while true; end" | ../fish --no-execute
|
|
|
|
|
|
2015-04-06 06:47:04 +00:00
|
|
|
|
# Comments allowed in between lines (#1987)
|
|
|
|
|
echo before comment \
|
|
|
|
|
# comment
|
|
|
|
|
after comment
|
|
|
|
|
|
2015-05-03 01:22:20 +00:00
|
|
|
|
# Backslashes are part of comments and do not join lines (#1255)
|
|
|
|
|
# This should execute false, not echo it
|
|
|
|
|
echo -n # comment\
|
|
|
|
|
false
|
|
|
|
|
|
2014-02-12 09:39:06 +00:00
|
|
|
|
function always_fails
|
|
|
|
|
if true
|
|
|
|
|
return 1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
always_fails ; echo $status
|
|
|
|
|
|