Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

8
  • Thanks for the response...!! Actually I am indeed trying to learn things in shell script...otherwise implementing array in Python is really a piece of cake. This was a big lesson that there exists some scripting language which does not support array :) One thing, the code you posted is giving a error - "syntax error at line 6: `$' unexpected" ... I am a little busy now, I would get it solved...plz dont bother. Commented Jun 17, 2014 at 10:51
  • @NoobGeek, the Bourne shell doesn't have the $(...) syntax. So you must indeed have the Bourne shell. Are you on Solaris 10 or before? Chances are you won't have a seq either. On Solaris 10 and earlier, you want /usr/xpg4/bin/sh to have a standard sh instead of a Bourne shell. Using seq that way is not very good either. Commented Jun 17, 2014 at 11:42
  • POSIX states that $ and ` are equivalent in command substitution: link. And why is using of seq that way not good? Commented Jun 17, 2014 at 12:17
  • 3
    Yes in POSIX shells, you should prefer $(...) over `, but the OP's /bin/sh is probably a Bourne shell, not a POSIX shell. Beside seq not being a standard command, doing $(seq 100) means storing the whole output in memory, and that means it depends on the current value of $IFS containing newline and not containing digits. Best to use i=1; while [ "$i" -le 100 ]; ...; i=$(($i + 1)); done (though that wouldn't work in the Bourne shell either). Commented Jun 17, 2014 at 13:51
  • 1
    @Daenyth I would say quite the contrary: learning bashisms first, and then portable /bin/sh syntax later, tends to make people think it's okay to use the wrong #!/bin/sh shebang, and then breaks their scripts when other people try to use them. You'd be well advised to not post this kind of flamebait. :) Commented Oct 30, 2015 at 13:39