I know this is probably top of the Dummies questions!


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers I know this is probably top of the Dummies questions!
# 1  
Old 11-13-2010
Question 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... Smilie
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?

Code:
echo -n "Enter cityName: "
read cityName
   echo "$cityName" >> $thefile
   echo >> $thefile
   cat >> $thefile

Moderator's Comments:
Mod Comment please use "code" tags!

Last edited by DukeNuke2; 11-14-2010 at 12:29 PM.. Reason: I thought it was worded poorly and wanted to improve the question to make it clearer
# 2  
Old 11-13-2010
Quote:
echo >> $file & cat >> $file
Code:
# 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}


Last edited by methyl; 11-13-2010 at 09:35 PM.. Reason: Ensure all variables have an example value
This User Gave Thanks to methyl For This Post:
# 3  
Old 11-13-2010
That is so sweet of you. Now I get it .... Thank you so much!Smilie

I love this stuff and I really want to understand it. It is very intriguing, but sometimes I get so frustrated. Smilie
# 4  
Old 11-14-2010
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:
Code:
{ echo "$cityName"
  echo
  cat "$theotherfile"
} >> "$thefile"

There are other ways too:
Code:
echo "$cityName

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

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

or
Code:
echo "$cityName
" | cat - "$theotherfile" >> "$thefile"

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

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

or:
Code:
cat << EOF >> "$thefile"
$cityName

$(cat "$theotherfile")
EOF

or (bash/ksh93)
Code:
cat <(echo "$cityName";echo) "$theotherfile" >> "$thefile"


Last edited by Scrutinizer; 11-14-2010 at 06:53 AM..
# 5  
Old 11-14-2010
Thanks Guys!
I like this: Makes a lot more sense.

echo "$cityName
" | cat - "$theotherfile" >> "$thefile"
 
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

dummies question

Please help to answer some highlighted question below. 1. How to create more than 1 partition in a single hard disk? 2. How to format the created partition to be viewable like in windows C: or D: ? 3. How to use pen drive in unix environment? 4. How to find a file starting with... (8 Replies)
Discussion started by: jimmyysk
8 Replies

2. AIX

Need a list of top 10 CPU using processes (also top 10 memory hogs, separately)

Okay, I am trying to come up with a multi-platform script to report top ten CPU and memory hog processes, which will be run by our enterprise monitoring application as an auto-action item when the CPU and Memory utilization gets reported as higher than a certain threshold I use top on other... (5 Replies)
Discussion started by: thenomad
5 Replies

3. AIX

Top command in AIX 4.2 (no topas, no nmon, no top)?

Is there a 'top' command equivalent in AIX 4.2 ? I already checked and I do not see the following ones anywhere: top nmon topas (1 Reply)
Discussion started by: Browser_ice
1 Replies

4. UNIX for Dummies Questions & Answers

I am real Dummies , I am Questions

I want to know data about 1. Overview 2. Process Management 3. Memory Management 4. File System Management 5. Secondary Storage Management 6. Protection and Security Systems of UNIX OS Thank Alot. (1 Reply)
Discussion started by: coolmara04
1 Replies

5. Solaris

Solaris for dummies

Is there one command that will display all system information on a Solaris host running Solaris 8? System information such as model, memory, CPU, disk space etc. etc. (2 Replies)
Discussion started by: mita
2 Replies

6. Shell Programming and Scripting

Perl for Dummies

Hi all. iam new to this and i want to learn perl Any good website out there ?? anything will do thanks :( (1 Reply)
Discussion started by: perleo
1 Replies

7. UNIX for Dummies Questions & Answers

scripts for dummies

í have no idea how to write a script. can someone help? how would i write a script that will do the following commands mkdir temp cp * temp cd temp ls i want to be able to do a set of commands by typing in only one command. i´m a windows user that is trying to learn unix, finally :P so... (6 Replies)
Discussion started by: eeldivady
6 Replies
Login or Register to Ask a Question