LANGUAGE » SHELL_SCRIPT » FISH
Flow control
Condition
[[ ]] does not exist. [ ] exist but test is preferred.
fish
if not grep fish /etc/shells
echo 'No fish'
else if test $number -gt 5 -o $argv[1] = 'string is equal'
echo Complex condition
else
echo Got nothing
endTo check if directory is empty or not (reference):
fish
if test -n "$(find $DIR -maxdepth 0 -empty)"
echo "$DIR is empty!"
endFor loop
Loop files:
fish
for file in *.txt
cp $file $file.bak
endLoop list of numbers:
fish
for x in (seq 5)
touch file_$x.txt
endBreak:
fish
for var in a b c
if break_from_loop
break
end
endWhile loop
fish
while true
echo 'Loop forever'
endRead file line by line in loop:
fish
while read --line keyvalue
export $keyvalue
end <~/.local/environmentSwitch
fish
switch (uname)
case Linux
echo Hi Tux!
case Darwin
echo Hi Hexley!
case FreeBSD NetBSD DragonFly
echo Hi Beastie!
case '*'
echo Hi, stranger!
end