I know this is probably top of the Dummies questions!

Hello:
I am a very new Newbie. This is not a homework question.
The assignment question was actually on the use of the 2 different inputs 'read' and 'cat' ... that I know and turned in an hour ago. I don't need help with that. My question, like I said, probably sounds really dumb to most of you!!! It is no problem if you feel uncomfortable answering, but like I told you the homework question, I answered. It is my curiosity that is driving me crazy on a Saturday night and I am impatience... :smiley:
I am just wondering why you would want to redirect the output from 'echo' and then do it again for 'cat'. It seems pointless; I am missing something somewhere... Does it even matter in this example? Am I reading too much into it?

echo -n "Enter cityName: "
read cityName
   echo "$cityName" >> $thefile
   echo >> $thefile
   cat >> $thefile
# Append the contents of the Environment Variable called "${variable_name}"
# to the file called "${file}"
variable_name="the text I want to append"
echo "${variable_name}" >> ${file}

# Append the contents of the file called "${the_other_file}"
# to the the file called "${file}".
the_other_file="the_name_of_the_other_file"
cat "${the_other_file}" >> ${file}

That is so sweet of you. Now I get it .... Thank you so much!:b:

I love this stuff and I really want to understand it. It is very intriguing, but sometimes I get so frustrated. :slight_smile:

To add, the reason that you have to specify >> multiple times is that this kind of redirection is for one command only.

To redirect a group of commands in one go you can do this:

{ echo "$cityName"
  echo
  cat "$theotherfile"
} >> "$thefile"

There are other ways too:

echo "$cityName

$(cat "$theotherfile")" >> "$thefile"

or

printf "$cityName\n\n$(cat "$theotherfile")\n" >> "$thefile"

or

echo "$cityName
" | cat - "$theotherfile" >> "$thefile"

or

printf "$cityName\n\n" | cat - "$theotherfile" >> "$thefile"

or

exec 3>&1 >> "$thefile"
echo "$cityName"
echo
cat "$theotherfile"
exec >&3

or:

cat << EOF >> "$thefile"
$cityName

$(cat "$theotherfile")
EOF

or (bash/ksh93)

cat <(echo "$cityName";echo) "$theotherfile" >> "$thefile"

Thanks Guys!
I like this: Makes a lot more sense.

echo "$cityName
" | cat - "$theotherfile" >> "$thefile"