3

I run GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu). A very simple script called from cmd line with at least 3 arbitrary arguments:

#!/bin/bash

n_arg=$#
arr=("$@") 
AA=${arr[0]}   # CHANGED FROM AA=S{arr[0]}
BB=${arr[1]}   # CHANGED FROM BB=S{arr[1]}

for (( i = 2; i < "$n_arg"; i++ )); do
    printf "%d   %s   %s   %s\n" $i $AA $BB  ${arr[i]}  # <- line 9
    # printf "%d   %s   %s   %s\n" $i "$AA" "$BB"  ${arr[i]}  # ALSO TRIED
done
exit 0

yields an error as shown below:

$ script.sh 10 2 13 443
./script.sh: line 9: printf: S{arr[0]}: invalid number
./script.sh: line 9: printf: S{arr[1]}: invalid number
2    0   0   13
./script.sh: line 9: printf: S{arr[0]}: invalid number
./script.sh: line 9: printf: S{arr[1]}: invalid number
3    0   0   443

I can see that the value of the first and second array elements passed to AA and BB respectively seems to pose a prbm I don't quite scope. I did try: AA="S{arr[0]}" When I type in the code in interactive mode, everything goes smoothly.

3
  • 3
    S? Do you mean $? As, in AA=${arr[0]} Commented Jun 23, 2015 at 20:44
  • 3
    Sounds like you need glasses or a better font. =) Commented Jun 23, 2015 at 20:45
  • ProggyFont rules. Commented Jun 23, 2015 at 20:45

1 Answer 1

1

S looks like $, especially when you're tired. I use a font designed to clearly distinguish homoglyphs like that -- highly recommended.

Arrays are not part of the POSIX shell standard. You can roll your own polyfill, or use a pre-fab one.

Sign up to request clarification or add additional context in comments.

2 Comments

Just a vaguely lame and off topic but real short comment: .... I took yr advice and downloaded/installed the proggy TTF. It looks really bad in terminal on my 1680x1050 display, because due to high screen res I have to increase font size from default 12 to 16 to be able to read clearly ... So unless there is a solution to legibly scale TTF available in terminal , it's a no go for me. Pity but advice much appreciated.
@Cbhihe Similar situation here, 1920x1080 FHD, the font looks jagged at high point size. I've come to consider that a benefit, though. Not only do I get a bit of daily nostalgia from the 1993 BBS feel (which even strangers comment on), but I can clearly read it from far away with my wireless keyboard. But I guess it's like snails in butter -- an acquired taste. That said, there are a few really good anti-aliased monospace programmer's fonts. Here's a great article listing 10 of them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.