Another Simple BASH command I don't understand. Help?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Another Simple BASH command I don't understand. Help?
# 1  
Another Simple BASH command I don't understand. Help?

I have a text file called file1 which contains the text: "ls -l"
When I enter this command:
Code:
bash < file1 > file1

file1 gets erased. However if I enter this command:
Code:
bash < file1 > newfile

the output from "ls -l" is stored in newfile. My question is why doesn't file1's text ("ls -l") get replaced with the output of the ls -l command?

Last edited by Franklin52; 03-11-2011 at 04:42 AM.. Reason: Please use code tags
# 2  
For that the OS would have to execute your instructions sequentially... This is what multiprocessing OS is all about (remember? UNIX is a preemptive multitasking, multiprocessing OS...)
# 3  
I don't know what a preemptive, multitasking, multiprocessing OS is let alone how it relates to my question
# 4  
Quote:
Originally Posted by phunkypants
I have a text file called file1 which contains the text: "ls -l"
When I enter this command:
bash < file1 > file1
file1 gets erased. However if I enter this command:
bash < file1 > newfile
the output from "ls -l" is stored in newfile. My question is why doesn't file1's text ("ls -l") get replaced with the output of the ls -l command?

if we look at how the second version works:
1. bash will create a empty file called newfile, ready to accept the output from your commands.
2. bash will open the file1 to get input.
3. bash will run the ls -al that it found in file1.
4. the output of ls -al is sent to the output file called newfile.


so if we then look at the "broken" first version:
1. bash will create an empty file called file1. (over writing your "ls -al" command)
2. bash will open the file1 (now empty)
3. bash will find nothing to do.
4. bash will send the output of nothing to the new file called file1
 

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #468
Difficulty: Medium
Both Ethernet and IPv4 use an all-zeros broadcast address to indicate a broadcast packet.
True or False?

8 More Discussions You Might Find Interesting

1. OS X (Apple)

Don't understand the practical difference between command aliases and environmental variables

Hey, I'm recently learning Unix from the video course by Kevin Scoglund. I'm stuck at the moment where he goes into Environmenat variables. I have some issues with understanding what's the essential difference between EV and command aliases: for instance, by writing the command alias ll='ls... (3 Replies)
Discussion started by: scrutinizerix
3 Replies

2. UNIX for Dummies Questions & Answers

I don't understand conditions :(

Hi there, I have a very general question. I'm rather new to (bash) shell scripting and I don't understand how conditions work... I've read numerous tutorials but I don't get it. I really don't. Sometime what I do works, sometime it doesn't and that's frustating. So what's the actual difference... (0 Replies)
Discussion started by: hypsis
0 Replies

3. Shell Programming and Scripting

Perl syntax that I don't understand.

I'm just trying to confirm that I understand someone's code correctly. If someone has code that says: $foo ||= mysub(); I'm assuming that it means if $foo is nothing or undef, then assign it some value via mysub(). If I'm wrong on this, please let me know. Also, what's the difference... (4 Replies)
Discussion started by: mrwatkin
4 Replies

4. Homework & Coursework Questions

I don't understand some basics..

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 1)find all lines in file ,myf that contain all the words cat dog and mouse in any order and start with the letter... (1 Reply)
Discussion started by: cudders
1 Replies

5. Shell Programming and Scripting

Don't understand how RS functions in awk

I learn using RS in awk to extract portion of file in this forum which is wonderful solution to the problem. However, I don't understand how exactly it operates. I don't quite understand the mechanism behind how searching for /DATA2/ can result in extracting the whole section under "DATA2" ... (3 Replies)
Discussion started by: joe228
3 Replies

6. Shell Programming and Scripting

don't understand a command "."

Hi all, I have a script with those two lines : test -f $PWD/mysetup.txt . $PWD/mysetup.txt I understand the first one, but could anyone explain me the role of the second one? All the thing I find is the usage : Thx in advance (3 Replies)
Discussion started by: Moumou
3 Replies

7. UNIX for Advanced & Expert Users

don't understand the unix script

if {"$my_ext_type" = MAIN]; then cd $v_sc_dir Filex.SH $v_so_dir\/$v_fr_file Can somebody tell me what does this suggest. I am pretty new to unix and I am getting confused. What i understood from here is If we have a file extension name as MAIN which we have then we change the directory to... (1 Reply)
Discussion started by: pochaman
1 Replies

8. UNIX for Dummies Questions & Answers

i don't understand the "sort" command

i have been trying to understand this chapter titled "Searching for Files and Text" for a few weeks now. unfortunately, this chapter is one of those things, that no matter how hard you try and how long you try for, you are incapable of understanding (at least in my case) this entire chapter,... (2 Replies)
Discussion started by: xyyz
2 Replies

Featured Tech Videos