LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   temporarily broken bash, need explanation (https://www.linuxquestions.org/questions/linux-newbie-8/temporarily-broken-bash-need-explanation-814149/)

krack3rz 06-14-2010 06:48 PM

temporarily broken bash, need explanation
 
i was fiddling with some new commands i learned and typed something weird. Then bash broke on me for a while. here's the command i typed while in /bin

bash > less

i believe i was in "sudo su" as the moment. i want to understand this because when I typed it bash didnt work. i tried to type "ls" after and it didnt result in anything. but thats not all it didnt receive any commands.
Was this a crash? and why/how did it fix itself after i logged off.

any info. would be helpful.
Running: Linux [Gnome]

exvor 06-14-2010 07:17 PM

No it did not crash. When you type bash in at a command prompt it will create a new instance of bash running on the terminal. The command bash > less will redirect the output for bash into the input for less. Since less will read so many lines from stdout and then wait for the user to hit a key to continue.

Because in essence you were then in less and less does not pass keyboard commands out to bash by default you had a terminal waiting for output from bash and no way to input anything into bash thus no output. You may have had a way to terminate less but I am not on a linux system ATM so I am not sure.

onebuck 06-14-2010 07:18 PM

Hi,
Let me man that for you;

Quote:

excerpt 'man bash';
NAME

bash - GNU Bourne-Again SHell SYNOPSIS

bash [options] [file] COPYRIGHT

Bash is Copyright (C) 1989-2004 by the Free Software Foundation, Inc. DESCRIPTION

Bash is an sh-compatible command language interpreter that executes commands read from the standard input or from a file. Bash also incorporates useful features from the Korn and C shells (ksh and csh). Bash is intended to be a conformant implementation of the IEEE POSIX Shell and Tools specification (IEEE Working Group 1003.2).
Quote:

excerpt 'man less';

less - opposite of more SYNOPSIS

less -?
less --help
less -V
less --version
less [-[+]aBcCdeEfFgGiIJLmMnNqQrRsSuUVwWX~]
[-b space] [-h lines] [-j line] [-k keyfile]
[-{oO} logfile] [-p pattern] [-P prompt] [-t tag]
[-T tagsfile] [-x tab,...] [-y lines] [-[z] lines]
[-# shift] [+[+]cmd] [--] [filename]...
(See the OPTIONS section for alternate option syntax with long option names.)
DESCRIPTION

Less is a program similar to more (1), but which allows backward movement in the file as well as forward movement. Also, less does not have to read the entire input file before starting, so with large input files it starts up faster than text editors like vi (1). Less uses termcap (or terminfo on some systems), so it can run on a variety of terminals. There is even limited support for hardcopy terminals. (On a hardcopy terminal, lines which should be printed at the top of the screen are prefixed with a caret.) Commands are based on both more and vi. Commands may be preceded by a decimal number, called N in the descriptions below. The number is used by some commands, as indicated.
As you should know the '>' character is used for redirection. So your command 'bash > less' should be obvious if you read the 'man command' above.

I suggest that you look at the following links to aid you for future use in understanding;

Linux Documentation Project
Rute Tutorial & Exposition
Linux Command Guide
Utimate Linux Newbie Guide
LinuxSelfHelp
Getting Started with Linux
Bash Reference Manual
Advanced Bash-Scripting Guide
Linux Home Networking
Virtualiation- Top 10

:hattip:
The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!

geoff_f 06-15-2010 01:49 AM

Quote:

Originally Posted by exvor
The command bash > less will redirect the output for bash into the input for less.

No, you are confusing that with 'bash | less'. 'bash > less' will direct the output of the command 'bash' to a file called 'less' in the user's current directory.

krack3rz, bash is the underlying program that the terminal uses to run its operations. You don't need to run 'bash' from within the terminal; it's already running for you.

A good reference to understand bash is here: http://www.gnu.org/software/bash/manual/bashref.html.

onebuck, you'll need to change your Bash Reference Manual link to end in .html. It currently gets a 404 - Page Not Found.

onebuck 06-15-2010 07:37 AM

Hi,

Quote:

Originally Posted by geoff_f (Post 4003881)
<snip>

onebuck, you'll need to change your Bash Reference Manual link to end in .html. It currently gets a 404 - Page Not Found.

Thanks! I mangled it when copied originally.
Fixed!

student04 06-15-2010 01:33 PM

Quote:

Originally Posted by onebuck (Post 4003679)
Hi,
Let me man that for you;

As you should know the '>' character is used for redirection. So your command 'bash > less' should be obvious if you read the 'man command' above.

I suggest that you look at the following links to aid you for future use in understanding;

Linux Documentation Project
Rute Tutorial & Exposition
Linux Command Guide
Utimate Linux Newbie Guide
LinuxSelfHelp
Getting Started with Linux
Bash Reference Manual
Advanced Bash-Scripting Guide
Linux Home Networking
Virtualiation- Top 10

:hattip:
The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!

Why are you being so harsh? The original poster doesn't seem to know what > and | are, else they wouldn't be asking the question. And dumping man pages and links doesn't help if they don't know what to look for.

As geoff_f mentioned, running

Code:

$ bash > less
will invoke a new instance of the shell, but all non-error output will be saved to a file called 'less'. The command 'less' is not involved in any way. If you type 'exit' it will return you to the previous shell that ran the above command and all will be fine. If you check your current directory it will contain a file called 'less' which has all the output you did not see (the output you expected, and assumed was because bash broke).

Code:

$ pwd
/tmp/test
$ ls
poem.txt
$ cat poem.txt
Here's a text file with some text in it.
$ bash > less
$ pwd
$ ls
$ cat poem.txt
$ exit
exit
$ ls
less  poem.txt
$ cat less
/tmp/test
less
poem.txt
Here's a text file with some text in it.

The contents of the file 'less' contain four lines, which are the outputs of the three commands I ran after doing 'bash > less'.

Does this help clarify what you did?

-AM

onebuck 06-15-2010 02:09 PM

Hi,

Quote:

Originally Posted by student04 (Post 4004522)
Why are you being so harsh? The original poster doesn't seem to know what > and | are, else they wouldn't be asking the question. And dumping man pages and links doesn't help if they don't know what to look for.

<snip>

-AM

Please point out what or where you feel is harsh with my response to the OP? I never mentioned the '|' character. No, the OP was experimenting and not knowing what he/she was doing period. So get off the high horse. '<' Now that may seem harsh but not intended as so. Just a plain statement of fact. If you don't have something to contribute as to my posts to the OP then let it be. Wait, did I see a 'moderator' label. NO!

:hattip:

student04 06-15-2010 03:32 PM

Quote:

Originally Posted by onebuck (Post 4004561)
Hi,


Please point out what or where you feel is harsh with my response to the OP?

Wording such as, "let me man that for you", "as you should know", and "should be obvious" --in my opinion-- are condescending. This *should be obvious* to you ;) Sorry if you didn't intend it that way originally, that's just how it read to me in my head.

Quote:

I never mentioned the '|' character.
This is indeed true, but I don't see the relevance in mentioning this. You confused > for |.

Quote:

No, the OP was experimenting and not knowing what he/she was doing period. So get off the high horse. '<' Now that may seem harsh but not intended as so. Just a plain statement of fact. If you don't have something to contribute as to my posts to the OP then let it be. Wait, did I see a 'moderator' label. NO!

:hattip:
I did indeed have something to contribute, and it was pointing out that your post was misleading. So I gave my own example.

onebuck 06-15-2010 04:36 PM

Hi,

Quote:

Originally Posted by student04 (Post 4004646)
Wording such as, "let me man that for you", "as you should know", and "should be obvious" --in my opinion-- are condescending. This *should be obvious* to you ;) Sorry if you didn't intend it that way originally, that's just how it read to me in my head.

This is indeed true, but I don't see the relevance in mentioning this. You confused > for |.

I did indeed have something to contribute, and it was pointing out that your post was misleading. So I gave my own example.

That's your opinion about how things are worded. Get over it! You will find others do the same type of posting and it is not meant to be condescending. Loads of newbie's are not aware of the system documentation and sometimes need to have some things pointed out to them. We're not spoon feeding here but if you want to then by all means, do it. I didn't judge how your presentation(s) were made except for your attempt at spanking me when it's not justified or necessary.

I did not confuse the two characters but the OP did utilize the '>'. I posted excerpts for man 'bash' & the command 'less'. His redirect was faulty. I never addressed the '|' period. I did not confuse either. Your reading things into this. I've re-read what I posted so I feel what was presented is correct.

As far as contribution, re-read what I said. I never said anything about the information that you presented to the OP. I was speaking of your contributions or comments to ME. You are mixing my posts with other members therefore confused and trying to justify.

If you feel what I presented was misleading then point it out and I'll see if it can be clarified.
I could have expanded but at the time was directly addressing the usage by the OP;
Quote:

As you should know the '>' character is used for redirection. So your command 'bash > less' should be obvious if you read the 'man command' above.

[example] If this was the confusion by omission then;

As you should know the '>' character is used for redirection that will direct the output to the trailing file that you called 'less'. So your command 'bash > less' should be obvious if you read the 'man command' above for 'bash'. Where you are using the 'bash' which is "Bash is an sh-compatible command language interpreter that executes commands read from the standard input or from a file." the command structure of 'bash > less' will direct the output of the new bash sh to the file less not the command 'less'. But even then it should be obvious that the creation of a new sh will be created if you read the 'man bash'. If you are thinking it would be to the command 'less' then look at the pipe character '|'. The command 'less' will sit an wait for input.

'OP' you are misusing the commands and structure of the commands if you expected the 'less' command to be executed by use of the character '>'. As others have pointed out it would be the pipe '|' character used. Look at the suggested links. They will help. [/example]

@student04 if that pacifies then 'Enough said!'.
:hattip:

exvor 06-15-2010 04:56 PM

Yeah don't let the wording of some responses seam to be harsh, they are probably not ment that way. Sometimes my responses I will write into them some whimsiclness and it may come off as me being an ass.

Anyway I was thinking of bash | less indeed not bash > less.


All times are GMT -5. The time now is 09:00 PM.