Talk:Bash

From Wikipedia, the free encyclopedia

Contents

[edit] Install instructions?

I don't think that the Bash installation instructions should be part of this article — they just duplicate the same information in the bash distribution (and probably do an inadequate job of it). Does this kind of information really belong in an encyclopedia? --Neilc 07:56, 30 Nov 2004 (UTC)

I feel the same way. --Mark Bergsma 15:13, 30 Nov 2004 (UTC)
I've commented out the "How to install Bash" section for now, but the reason I added it in the first place was because Bash is often an add-on shell (i.e., it doesn't come with every UNIX system), so people who want to start using it need to download, build, and install it themselves. This is not hard to do if you are a programmer, but non-programmers often have no idea what to do with a tarball after they download it, even if they know in some abstract way that a "build and install" must be done. Perhaps a reduced summary of this section should remain to help such a user? — franl 16:55, 30 Nov 2004 (UTC)
Very well, but that still belongs in the documentation, not in an encyclopedia. Perhaps add a convenient link to it. --Mark Bergsma 20:05, 9 Dec 2004 (UTC)

[edit] How to test for file extensions

I suspect this is the wrong place for this (that's why I'm not putting it in the article) but this little tip needs to be better promoted, so if you know of a better place for it, please move it there. In any case...

When writing a bash script which should do different things based on the the extension of a file, the following pattern is helpful.

#filepath should be set to the name(with optional path) of the file in question
 
 ext=${filepath##*.}
 if [[ "$ext" == txt ]] ; then 
   #do something with text files
 fi

(My source for this is the slike.com Bash FAQ. Maybe this should go in the Wikibook on this subject, or in some kind of Bash Cookbook? --JesseW 21:54, 21 July 2005 (UTC)

I'd suggesting starting a new chapter in the wikibook.... how about wikibooks:Bourne Shell Scripting/Cookbook? Lupin 23:48, 21 July 2005 (UTC)
Ok, I've moved it there. That will be my first real edit to Wikibooks... Maybe something will get started... --JesseW 01:05, 22 July 2005 (UTC)

A note on the code above: - first, it's not correct if the file doesn't contain any dot. Like a file called "txt" will be said to have a .txt extension while it doesn't - second, it's a non sh syntax for which there is a better sh equivalent (it's preferable to write a script using a standard syntax rather that the syntax of one specific version of one specific shell implementation):

 case $filepath in
   ?*.txt)
     # do something with text files
     ;;
 esac

[edit] Linux vs. GNU/Linux

I can't help but feel that this change is in factual error. As Bash is a GNU product, on a presumptive non-GNU-based Linux system, it would not be the default shelll. Please don't turn this into a flamewar over the term GNU/Linux vs. the name Linux alone; this is merely an inquiry into whether a non-GNU-based Linux distribution would use Bash as its default shell. Jouster 20:45, 22 August 2005 (UTC)

I think its alright the way it is. You see, in my opinion, the word Linux here imply the kernel, not the who operating system. If it was the later, I think the edit would have been a mistake. Now, some bash tricks [1]

[edit] Bash commands

How about a list of Bash commands? --88.111.52.30 15:48, 29 December 2005 (UTC)

Probably not. Such a list is not particularly encyclopedic or interesting- Wikipedia is not a repository for manuals after all. --Maru (talk) Contribs 18:12, 30 December 2005 (UTC)
I think it'd be worth mentioning that using the help command will bring up Bash-integrated commands (which are noteworthy different than those in /bin ). Particularly, using foreground (fg) and background (bg). Likewise, how the shell interprets keybindings such as Ctrl-Z and Ctrl-C. 69.22.210.109 19:05, 25 July 2006 (UTC)

[edit] Pipes

I have to say that I'm a little disappointed by the lack of the discussion of pipes.

Agreed, more elaboration on pipes & filters, and their use vis-a-vis "everything is a file" and /proc would greatly improve this article. 69.22.210.109 19:07, 25 July 2006 (UTC)

[edit] Integer Mathematics

I don't really understand this:

"A major limitation of the Bourne shell is that it cannot perform integer calculations without spawning an external process. Bash can perform in-process integer calculations using the ((...)) command and the $[...] variable syntax, as follows:"

So it can't do calculations without spawning an external process, ok... but wait, here's how to do it 'in-process'? Confused. --Ling

Bourne can't do integer calcs in process, but Bash can. Masterdriverz 17:21, 13 May 2006 (UTC)

[edit] OpenBSD

Some of the bits in here don't work on OpenBSD, although they do on Linux.

Could you be more specific? Which bits don't work on OpenBSD? --maru (talk) contribs 00:05, 27 July 2006 (UTC)

[edit] Unsorted comments about the bash page

First, about the credit. I don't think any of the feature described in the page was of the bash authors' invention. Most if not all features are copied from other shells: ksh for the syntax, csh/tcsh for the history and user interface and one or two zsh features. Maybe those features would be better introduced in the ksh/csh/zsh pages instead.

Minor point:

it should be:

echo "$((...))" instead of echo $((...)) as bash performs word splitting upon arithmetic expansion in that case (contrary to pdksh or zsh for instance).

It may be good to say that $[...] shouldn't be used as it's not a standard sh syntax contrary to $((...)).

The exit status of ((...)) is 0 or 1 depending on whether the expression resolves to 0 or not (a non-zero expression means "true" so a 0 exit status). So ((1+1)) is true and ((1-1)) is false.

bash has several I/O redirection syntaxes that the traditional Bourne shell lacks. bash can redirect standard output and standard error at the same time using this syntax:

The Bourne shell doesn't lack that. bash is only providing with a short cut. &> foo (why didn't bash just used the same as csh or zsh: >& ?) is the same as > foo 2>&1.

<<< 'string' is inherited from ksh93 which inherited it from zsh which inherited it from rc.

The regular expression syntax is the same as that documented by the regex(7) man page.  

That regex man page when it exists documents several regexp formats. bash implements the POSIX extended regexps.

About startup scripts, it should be noted that some Linux distributions for instance may interfer with that by changing some default configure values at compile time (like enabling a system-wide bashrc or disabling the sourcing of bashrc on rsh or ssh connections).

[edit] Bash special characters

For example, the character % and & does have a special meaning. So, say I dump something to stdout, I need to escape those characters. It would be nice to have a list here because printf won't work as expected. Sure, I know you can do all the aliases you want. I know it's likely to have been listed in the docs, but I'm rather sure it could be a nice addition and does not seem to require much work by people having to deal with this all days. Thanks!
83.190.231.93 21:33, 11 December 2006 (UTC)