← prev | next →
smol_mazunki 2022-07-15 18:11:04
how does if and fi even work
smol_mazunki 2022-07-15 18:11:16
they’re commands, not syntax
smol_mazunki 2022-07-15 18:11:27
thecatvoid 2022-07-15 18:10:59
shell check said to use else if
huh
Shah_baaz2 2022-07-15 18:11:45
smol_mazunki 2022-07-15 18:06:02
if [ condition ]; then
command
elif [ condition2 ]; then
command2
elif [ condition3 ]; then
command3
else
command
fi
But this will work as a ladder condition2 will only run when condition1 is passed
That is what it was written on web
smol_mazunki 2022-07-15 18:11:47
else; if [ ]; then command; fi; fi
smol_mazunki 2022-07-15 18:12:24
or else if [ ]; then command; fi?
thecatvoid 2022-07-15 18:12:27
smol_mazunki 2022-07-15 18:11:16
they’re commands, not syntax
its shell builtins
thecatvoid 2022-07-15 18:12:32
like cd
smol_mazunki 2022-07-15 18:12:54
Shah_baaz2 2022-07-15 18:11:45
But this will work as a ladder condition2 will only run when condition1 is passed
That is what it was written on web
condition2 will only run if condition1 failed, yes
smol_mazunki 2022-07-15 18:13:16
do you want to run command1 if either condition1 or condition2 passes?
smol_mazunki 2022-07-15 18:13:34
thecatvoid 2022-07-15 18:12:32
like cd
thought cd was a command too
marcotrosi 2022-07-15 18:14:14
mendel7 2022-07-15 17:34:16
windows is spyware and shouldn’t be used
so one of many reasons to use Linux
thecatvoid 2022-07-15 18:14:29
smol_mazunki 2022-07-15 18:13:34
thought cd was a command too
try sudo cd
thecatvoid 2022-07-15 18:14:34
not doas cd
thecatvoid 2022-07-15 18:14:45
it wont tell that
smol_mazunki 2022-07-15 18:14:49
thecatvoid 2022-07-15 18:14:29
try sudo cd
doesn’t that fail because of new euid
thecatvoid 2022-07-15 18:14:54
thecatvoid 2022-07-15 18:15:22
smol_mazunki 2022-07-15 18:14:49
doesn’t that fail because of new euid
it fails because it cant find the command called cd
smol_mazunki 2022-07-15 18:15:27
thecatvoid 2022-07-15 18:15:22
it fails because it cant find the command called cd
huh
smol_mazunki 2022-07-15 18:15:43
sudo su -c ‘cd’
thecatvoid 2022-07-15 18:15:46
if you do
sh -c ‘cd whatever’
it will cd and exit
smol_mazunki 2022-07-15 18:15:49
smol_mazunki 2022-07-15 18:15:43
sudo su -c ‘cd’
doesn’t work btw
smol_mazunki 2022-07-15 18:15:53
thecatvoid 2022-07-15 18:15:46
if you do
sh -c ‘cd whatever’
it will cd and exit
yeah xd
smol_mazunki 2022-07-15 18:16:00
and return to old cwd
thecatvoid 2022-07-15 18:16:06
yup
Shah_baaz2 2022-07-15 18:18:23
3 different condition with no dependency with each other
🙁
Shah_baaz2 2022-07-15 18:18:47
If
Else
Else
Fi
Shah_baaz2 2022-07-15 18:19:05
Shah_baaz2 2022-07-15 18:18:47
If
Else
Else
Fi
With no elif
smol_mazunki 2022-07-15 18:19:43
Shah_baaz2 2022-07-15 18:18:47
If
Else
Else
Fi
if [ a ]; then
run1
fi
if [ b ]; then
run2
fi
if [ c ]; then
run3
fi
smol_mazunki 2022-07-15 18:19:49
you mean this?
smol_mazunki 2022-07-15 18:20:20
could also just
test a && run1
test b && run2
test c && run3
smol_mazunki 2022-07-15 18:20:55
could also just
test a && run1; test b && run2; test c && run3
Shah_baaz2 2022-07-15 18:21:54
smol_mazunki 2022-07-15 18:19:43
if [ a ]; then
run1
fi
if [ b ]; then
run2
fi
if [ c ]; then
run3
fi
Yes but like this
if [ a ]; then
run1
Else
if [ b ]; then
run2
Else
if [ c ]; then
run3
Fi
smol_mazunki 2022-07-15 18:22:21
Shah_baaz2 2022-07-15 18:21:54
Yes but like this
if [ a ]; then
run1
Else
if [ b ]; then
run2
Else
if [ c ]; then
run3
Fi
what do you mean by else anyway
smol_mazunki 2022-07-15 18:23:19
if [ main condition ]; then
main_command
else
if [ secondary1 ]; then
command1
else
command2
fi
fi
← prev | next →