Help with a Bash Script Error: ‘command not found’

0
1
Asked By ScriptNewbie92 On

Hey everyone! I'm new to scripting and I created a basic bash script aimed at checking for disconnected file shares on my Proxmox VE host. The goal is to automatically remap any missing shares, especially if my NAS powers on after the Proxmox host, so I don't have to manually run `mount -a`. I'm proud of my first attempt beyond simple scripts but I'm encountering an annoying error: "./Auto-Mount.sh: line 59: : command not found" whenever it detects a missing share. Interestingly, the error doesn't appear when all shares are connected. I've pinpointed the line causing the issue (line 59: `if "$any_still_false"; then`), but I can't figure out why this is happening. I'd appreciate any advice or even critiques on my code! Also, let me know if my code formatting is clear or if I need to adjust anything.

6 Answers

Answered By LogicNinja42 On

Your variable is currently treated as a string, so you should either leave it unquoted or compare it properly, like this: `if [[ "${myvar}" == "true" ]]; then ... fi`. This should resolve the issue.

Answered By BashBuff23 On

Make sure you add `eval` to your command, this way the variable gets executed as a command. It's essential for making sure the conditions are evaluated correctly.

Answered By ProTipPal On

When posting code, use code fences instead of indentation; it's much cleaner and reduces errors. About your error, the line `if "$any_still_false"; then` is treating it as a command, which it can't find when it's an empty string. Use `bash -x` to trace the evaluations and find where the logic is going off.

Answered By CodingGuru23 On

For what you're trying to achieve, consider looking into systemd units instead. You might want to check out one-shot units with parameters like `Restart=on-failure`. It could simplify the management of your mounts!

Answered By DebuggingPro On

Use `bash -v script` and `bash -x script` for tracing your script. Also, remember that if you use quotes, you'll need to escape them inside quotes. For example: `X="test "Name" test"`.

Answered By HelpfulHacker17 On

Have you tried running your script through ShellCheck? It's a fantastic way to catch syntax issues and other common problems in bash scripts.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.