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
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.
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.
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.
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!
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"`.
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
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically