well from my understanding the script (firstline) needs to take on 2 arguments which can be done through $. So $1 could be argument 1 and $2 can be argument 2. The script needs to take the first argument and insert it into the very top - teh first line of my second file. I believe this can done by using the echo function by getting the line from $1 and then inserting it into $2 bu cant quite put my finger on it.
I believe this can done by using the echo function by getting the line from $1 and then inserting it into $2 bu cant quite put my finger on it.
That is the essential nub of the problem. For instance, lastline would be a piece of cake
Code:
#!/bin/sh
echo "$1" >>"$2"
because the >> operator appends the data. But this problem says we have to put the data as a new first line.
So my solution says, okay I know what the contents of the new file should look like
Code:
echo "$1" | cat - "$2"
but that output just dissappears, so we need to put it somewhere, like a temporary file, here $$ will be used as a temporary file as it's a unique number, ie the pid of the shell.
Code:
echo "$1" | cat - "$2" >$$
but the problem says that this new output should be in the original file, so what we do is rename this temporary file to the original file name, which as a byproduct is (a) atomic (b) unlinks the original file