Problem in making a script

Nils Kassube kassube at gmx.net
Wed Jun 29 14:03:49 UTC 2011


amritpal pathak wrote:
>  I tried syntax given by you as:
> 
>  TEMP=$(mktemp)
> head -n $(($4 - 1)) "$abc.tex" > "$TEMP"

That should be

head -n $((4 - 1)) "abc.tex" > "$TEMP"

The original variable in my syntax was LINENUM and if you want to insert 
the value of a variable, you put a "$" sign in front of the variable 
name. The shell would then replace the $LINENUM with 4 in your example. 
Now if you want to replace the variable with a value you should also 
remove the "$" sign. Please read one of the bash manuals to understand 
the syntax. I sent links to the manuals in one of my previous mails.

And that's the same problem in the other lines:

> LEN=$(cat "$abc.tex"|wc -l)

That should be 

LEN=$(cat "abc.tex"|wc -l)

> tail -n $(($LEN - $4)) "$abc" >> "$TEMP"

That should be

tail -n $(($LEN - 4)) "abc" >> "$TEMP"

> mv "$TEMP" "$abc.tex"

That should be

mv "$TEMP" "abc.tex"

> name is accepted from user.but when i ran it as "sh filename.sh",it
> gave following error.

And here you should use "bash filename.sh" because I don't know if any 
of the commands above are specific to bash. It depends on your standard 
shell if it makes a difference. usually bash is the standard shell for 
the command line but e.g. for init scripts it is dash which doesn't know 
about the bash extensions.


Nils




More information about the ubuntu-users mailing list