Problem in making a script

Nils Kassube kassube at gmx.net
Thu Jun 30 08:37:21 UTC 2011


amritpal pathak wrote:
>                                                                But
> still i am little bit confuse to understand it "how it is
> happening".Please sir,tell me what each line is doing .It will make
> me fully understand it
> 
> TEMP=$(mktemp)

Make a temporary file which doesn't conflict with existing files.

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

Copy the first lines from the original file to the temporary file.

> echo "$fname" >> "$TEMP"

Append the user input to the temporary file.

> LEN=$(cat "abc.tex"|wc -l)
> tail -n $(($LEN - 4)) "abc.tex" >> "$TEMP"

Append the remaining lines from the original file to the temporary file.

> mv "$TEMP" "abc.tex"

Replace the original file by the temporary file.

If you want to learn more about the individual commands, please read the 
man pages:

man mktemp head echo cat wc tail mv


Nils




More information about the ubuntu-users mailing list