help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] how to understand the xargs


From: lina
Subject: Re: [Help-bash] how to understand the xargs
Date: Tue, 27 Dec 2011 23:27:35 +0800
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111114 Icedove/3.1.16

On Tuesday 27,December,2011 11:16 PM, Greg Wooledge wrote:
On Tue, Dec 27, 2011 at 11:12:31PM +0800, lina wrote:
#!/bin/sh

for i in {1..10} ; do
Brace expansion is a bash feature, not a /bin/sh feature.  When you put
#!/bin/sh at the top of your script, you are telling the operating system
to use /bin/sh as the interpreter when you run the script.  And /bin/sh
won't understand brace expansions.

If you wish to use bash features in your scripts, you must use

#!/bin/bash

or

#!/usr/bin/env bash

as your shebang.  This will make the operating system run bash to interpret
your script.

BTW, on script I used to use for i in $(seq 10)
just recent trying to learn more, so do some practice.
seq(1) is Linux-only.  Some other OSes have jot(1) instead, but both of
those are nonstandard (and they have incompatible syntax).

The correct way to count to 10 in /bin/sh is:

i=1
while [ $i -le 10 ]; do
   ...
   i=$((i+1))
done

Thanks, but


$ ./b.sh
./b.sh: 7: ./b.sh: i+1: not found
./b.sh: 5: [: -lt: unexpected operator

$ cat b.sh
#!/bin/sh

i=1

while [ $i -lt 10 ]; do

    i=$(i+1)

done

I don't know which parts is wrong.

Thanks again,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]