Декларация баш if

Примерен код

21
0

декларация баш if

and - &&
or - ||

# and example
if [ -r $1 ] && [ -s $1 ]
then
echo This file is useful.
fi

# or example
if [ $USER == 'bob' ] || [ $USER == 'andy' ]
then
ls -alh
else
ls
fi
14
0

в противен случай, ако синтаксис на оператор баш

#!/bin/bash
 
read -p "Enter your marks: " marks
 
if [ $marks -ge 80 ]
then
    echo "Very Good"
 
elif [ $marks -ge 50 ]
then
    echo "Good"
 
elif [ $marks -ge 33 ]
then
    echo "Just Satisfactory"
else
    echo "Not OK"
fi
7
0

ако и ако един удар

if [ "${STATUS}" != 200 ] && [ "${STRING}" != "${VALUE}" ]; then
2
0

баш, ако

#!/bin/bash

foo="qux"
bar="qux"

if [ "$foo" = "$bar" ]; then
    echo "The strings are equal."
else
    echo "The strings aren't equal."
fi
1
0

ако все още скрипт на обвивката bash

if [[ some condition ]]; then
  do_this
elif [[ another condition ]]; then
  do_that_a
elif [[ yet another condition]]; then
  do_that_b
else
  do_that_default_thing
fi

На други езици

Тази страница на други езици

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Íslensk
..................................................................................................................