1

I am using termux and it has no init system, i found a script to start crond when i start the app

if ! pgrep -f "crond" >/dev/null; then
echo "[Starting crond...]" && crond && echo "[OK]"
else
echo "[crond is running]"
fi

this code worked perfectly for bash shell.

I am currently using fish shell and tried using the same code in the fish equivalent of bash_profile AKA config.fish however, i got the error message

Missing end to balance this if statement
if ! pgrep -f "crond" >/dev/null; then
^
from sourcing file ~/.config/fish/config.fish
         called during startup

Please help me with translations, I'm reading through fish docs however it will take me a long time to get it right.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
Kenechukwu
  • 105
  • 1
  • 1
  • 12

2 Answers2

1

This answer by glenn-jackman is very helpful https://stackoverflow.com/a/29671880/5257034

i am able to run the code in config.fish without issues

my code

if ! pgrep -f $crond >/dev/null
echo "[Starting crond...]"; and crond; and echo "[OK]"
else
echo "[crond is running]"
end
Kenechukwu
  • 105
  • 1
  • 1
  • 12
  • 1
    The semicolon at the end of the `if` isn't needed. Nor is it needed after the `echo "[crond is running]"`. – Kurtis Rader Apr 14 '19 at 18:43
  • thanks for troubleshooting my code, I removed the semicolons where you mentioned and the code ran fine! hope you don't still think i didn't make an effort – Kenechukwu Apr 14 '19 at 20:05
1

You should start with the tutorial. There you will learn that if blocks look like this:

if pgrep -f "crond" >/dev/null
    do_something
end
Community
  • 1
  • 1
Kurtis Rader
  • 6,734
  • 13
  • 20