Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
06-22-2017, 10:40 AM
|
#1
|
LQ Newbie
Registered: Jun 2017
Posts: 16
Rep:
|
if you could help with this
I have stuck on symbols in a sentence and there is an argument my answers and my "friends" there was a discussion.I want to opened my mind because i confusing if something is right or wrong.I wrote cases with a,b,c etc.I want to tell me which one is right and which one is wrong because i have lost the sense and why it isnt.I with my friends are doing this and we have different results.Example a) is right , b) isnt right because...There are traps on those and i would be greatful if you could help with this.I have analize it much this issue but not sure because there was conflicts.Thanks a lot i appreciate if you could help. a)
Code:
cat file2.txt > A | B
b)
Code:
B 2> file3.txt | A >file1.txt 2> file2.txt
c)
Code:
A 2< file1.txt d) A | B | C <file3.txt
e)
Code:
A < file1.txt ; B < file2.txt
f)
Code:
A<file2.txt| while read x < file1.txt; do echo x "x is $x"; done
Last edited by ektoren; 06-22-2017 at 10:48 AM.
|
|
|
06-22-2017, 10:45 AM
|
#2
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
|
you really need to learn how to use code blocks and format that better because that is hard to read.
Code:
cat file2.txt > A | B b) B 2> file3.txt | A >file1.txt 2> file2.txt c) A 2< file1.txt d) A | B | C <file3.txt e) A < file1.txt ; B < file2.txt f) A<file2.txt| while read x < file1.txt; do echo x "x is $x"; done
tell your friend(teacher) .. never mind.
| <-- that is called a pipe it directs output of one program into the input of another program.
> and >> are called redirection it takes standard input and output (IO) and E(rror) and redirects it to wherever you tell it to go.
Quote:
0 - stdin
1 - stdout
2 - stderr
|
or strings and redirects it into a file
Code:
echo "this is a string" > fileName
which is standard output and redirects it into a file.
Last edited by BW-userx; 06-22-2017 at 11:58 AM.
|
|
|
06-22-2017, 10:49 AM
|
#3
|
LQ Newbie
Registered: Jun 2017
Posts: 16
Original Poster
Rep:
|
Quote:
Originally Posted by BW-userx
you really need to learn how to use code blocks and format that better because that is hard to read.
Code:
cat file2.txt > A | B b) B 2> file3.txt | A >file1.txt 2> file2.txt c) A 2< file1.txt d) A | B | C <file3.txt e) A < file1.txt ; B < file2.txt f) A<file2.txt| while read x < file1.txt; do echo x "x is $x"; done
tell your friend(teacher) .. never mind.
| <-- that is called a pipe it directs output of one program into another
> and >> are called redirection it takes stdout and redirects it to wherever you tell it to go.
|
its ok now?Yes thanks but it has syntax error or not all of the above i wrote?which are right which wrong
Last edited by ektoren; 06-22-2017 at 10:51 AM.
|
|
|
06-22-2017, 11:12 AM
|
#4
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
|
Quote:
Originally Posted by ektoren
its ok now?Yes thanks but it has syntax error or not all of the above i wrote?which are right which wrong
|
OK i updated page I can see it now.
I'm gathering that you are wanting to know which code works and which does not.
Here, let me try to teach you how to take that information and put it to the test so you can learn how to rely on your own self judgments.
first off you'll have to create a test file or files with data inside of it using the same naming conventions as your questions. then using your command line in a terminal just run the code and check for the results.
I'll use a file already created. Because for the first one it has to have information inside if to even do anything. else you'll get empty files.
Code:
yahoo.com
75.126.162.205
google.com
http://www.linuxquestions.org
linuxquestions.org
Results A
Code:
userx%slackwhere ⚡ testingmefiles ⚡> cat info.txt > A | B
bash: B: command not found
userx%slackwhere ⚡ testingmefiles ⚡>
Results B
Code:
userx%slackwhere ⚡ testingmefiles ⚡> B 2> file3.txt | A >file1.txt 2> file2.txt
userx%slackwhere ⚡ testingmefiles ⚡> ls
A file1.txt file2.txt file3.txt
userx%slackwhere ⚡ testingmefiles ⚡> cat A
yahoo.com
75.126.162.205
google.com
http://www.linuxquestions.org
linuxquestions.org
userx%slackwhere ⚡ testingmefiles ⚡> cat file1.txt
userx%slackwhere ⚡ testingmefiles ⚡> cat file2.txt
bash: A: command not found
userx%slackwhere ⚡ testingmefiles ⚡> cat file3.txt
bash: B: command not found
userx%slackwhere ⚡ testingmefiles ⚡>
Results C
Code:
userx%slackwhere ⚡ testingmefiles ⚡> A 2< file1.txt d) A | B | C <file3.txt
bash: syntax error near unexpected token `)'
userx%slackwhere ⚡ testingmefiles ⚡> ls
A file1.txt file2.txt file3.txt
userx%slackwhere ⚡ testingmefiles ⚡>
Results E
Code:
userx%slackwhere ⚡ testingmefiles ⚡> A < file1.txt ; B < file2.txt
bash: A: command not found
bash: B: command not found
userx%slackwhere ⚡ testingmefiles ⚡>
Results F
Code:
userx%slackwhere ⚡ testingmefiles ⚡> A<file2.txt| while read x < file1.txt; do echo x "x is $x"; done
bash: A: command not found
userx%slackwhere ⚡ testingmefiles ⚡>
now you can determine what works and what does not. You just need to figure out why?
Last edited by BW-userx; 06-22-2017 at 11:18 AM.
|
|
|
06-22-2017, 11:15 AM
|
#5
|
LQ Newbie
Registered: Jun 2017
Posts: 16
Original Poster
Rep:
|
Quote:
Originally Posted by BW-userx
OK i updated page I can see it now.
I'm gathering that you are wanting to know which code works and which does not.
Here, let me try to teach you how to take that information and put it to the test so you can learn how to rely on your own self judgments.
first off you'll have to create a test file or files with data inside of it using the same naming conventions as your questions. then using your command line in a terminal just run the code and check for the results.
I'll use a file already created. Because for the first one it has to have information inside if to even do anything. else you'll get empty files.
Code:
yahoo.com
75.126.162.205
google.com
http://www.linuxquestions.org
linuxquestions.org
Results A
Code:
userx%slackwhere ⚡ testingmefiles ⚡> cat info.txt > A | B
bash: B: command not found
userx%slackwhere ⚡ testingmefiles ⚡>
Results B
Code:
userx%slackwhere ⚡ testingmefiles ⚡> B 2> file3.txt | A >file1.txt 2> file2.txt
userx%slackwhere ⚡ testingmefiles ⚡> ls
A file1.txt file2.txt file3.txt info.txt
userx%slackwhere ⚡ testingmefiles ⚡> cat file3.txt
bash: B: command not found
userx%slackwhere ⚡ testingmefiles ⚡> cat file2.txt
bash: A: command not found
userx%slackwhere ⚡ testingmefiles ⚡> cat file1.txt
userx%slackwhere ⚡ testingmefiles ⚡>
Results C
Code:
userx%slackwhere ⚡ testingmefiles ⚡> A 2< file1.txt d) A | B | C <file3.txt
bash: syntax error near unexpected token `)'
userx%slackwhere ⚡ testingmefiles ⚡>
Results E
Code:
userx%slackwhere ⚡ testingmefiles ⚡> A < file1.txt ; B < file2.txt
bash: A: command not found
bash: B: command not found
userx%slackwhere ⚡ testingmefiles ⚡>
Results F
Code:
userx%slackwhere ⚡ testingmefiles ⚡> A<file2.txt| while read x < file1.txt; do echo x "x is $x"; done
bash: A: command not found
userx%slackwhere ⚡ testingmefiles ⚡>
now you can determine what works and what does not. You just need to figure out why?
|
results b?
|
|
|
06-22-2017, 11:24 AM
|
#6
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
|
Quote:
Originally Posted by ektoren
results b?
|
what is b doing in that code? Can you explain what it is doing to me so I know you know what it is doing?
the code is
Code:
B 2> file3.txt | A >file1.txt 2> file2.txt
|
|
|
06-22-2017, 11:30 AM
|
#7
|
LQ Newbie
Registered: Jun 2017
Posts: 16
Original Poster
Rep:
|
Quote:
Originally Posted by BW-userx
what is b doing in that code? Can you explain what it is doing to me so I know you know what it is doing?
the code is
Code:
B 2> file3.txt | A >file1.txt 2> file2.txt
|
it shows the output but next it shows mistake
|
|
|
06-22-2017, 11:33 AM
|
#8
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
|
1. seeing the set up on testing this code has not been fully established A and B maybe valid files. if not then which one actually throws the error, and not a message?
Unless as I think it is that C is a type O and because if you look at your questions you are missing that d -- you go from c to e and d is actually within c.
soooo that means.
Last edited by BW-userx; 06-22-2017 at 11:35 AM.
|
|
|
06-22-2017, 11:46 AM
|
#9
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
|
A is wrong because of this
Code:
cat file2.txt > A | B
the piping is wrong if B is not a command that is why you get the return message.
Code:
userx%slackwhere ⚡ testingmefiles ⚡> cat file2.txt > A | B
bash: B: command not found
B is wrong because there is no 'B' to work off of
Code:
B 2> file3.txt | A >file1.txt 2> file2.txt
But it too could be right because.
B 2> file3.txt
that is redirecting stderr of B which is not present into file3.txt
then pipes that into the next command which is
A>file1.txt which gets nothing because it is bogus code so it returns a stderr that gets sent to file2.txt
etc...
mod:
D)
Code:
A | B | C <file3.txt
this does what?
is there an A
is there an B
is there an C
is there a file3.txt
what does the pipes do
and what does the 'backwards' redirection do with file3.txt if there is such a file?
for pipes and redirection go back and look at post #2
Last edited by BW-userx; 06-22-2017 at 11:58 AM.
|
|
|
06-22-2017, 12:02 PM
|
#10
|
Moderator
Registered: Aug 2002
Posts: 26,193
|
Is this homework? Who says a) is right and b) isn't right?
Code:
a) cat file2.txt > A | B
To get you going for question a), A is a hypothetical file and B is a hypothetical program/script. As stated > redirects all output of the cat command which is the contents file2.txt into file A. If all output is redirected to a file then nothing can be piped to program B. From your previous text file
B = grep linuxquestions.org
Code:
cat info.txt | grep linuxquestions.org
Will output linuxquestions.org However
Code:
cat info.txt > file1.txt | grep linuxquestions.org
Outputs nothing since the output of the cat command is redirected to file1.txt. There is nothing wrong with the syntax except you might not see the desired output.
Can you explain question b)? Do you understand the difference between stdout and stderr?
Last edited by michaelk; 06-22-2017 at 12:33 PM.
Reason: added example
|
|
|
All times are GMT -5. The time now is 01:13 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|