I'm having trouble with a portion of my Bash script that results in an 'illegal number' error. Here's the snippet I'm working with:
```bash
var="nef892na9s1p9asn2aJs71nIsm"
for counter in {1..40}
do
var=$(echo $var | base64)
if [ $counter -eq 35 ]
then
echo $var | WC -c
fi
done
```
The error message I keep getting is 'illegal number: {1..40}'. Can someone help me figure out what's wrong?
4 Answers
Don't forget, the format for your range should be `{1..40..1}`. It's an easy fix, and it might clear up that error. Also, make sure there's no confusion with uppercase `WC`, as it should be lowercase `wc`, unless you're specifically referencing a different command with that name.
I ran a similar version of your script, and it worked fine on my Mac with an older version of Bash. Just to cover all bases, check for any unbalanced quotes or brackets in the parts of the script leading up to this section. That can often trip up Bash.
Make sure you're actually running the script in Bash. Sometimes, other shells might lead to compatibility issues with the syntax you're using. You might also want to try using `var=$(base64 <<< "$var")` to eliminate the call to `echo`, which can clean things up a bit.
Good point! I need to double-check my shell.
It looks like you're missing the shebang at the start of your script. Make sure you have `#!/bin/bash` at the very top. It sets the interpreter for your script and can help avoid errors like this one. The rest of your script seems fine, but just ensure you're executing it in the right environment.
I do have the shebang! I just pasted the part causing issues.
Thanks! I’ll try changing it to lowercase and see if that helps.