Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #274929
| From | Greg Wooledge <greg@wooledge.org> |
|---|---|
| Newsgroups | linux.debian.user |
| Subject | Re: Using terminal commands - corner cases |
| Date | 2024-11-27 15:50 +0100 |
| Message-ID | <JNrwB-c0uz-5@gated-at.bofh.it> (permalink) |
| References | <JNoyJ-bYHw-7@gated-at.bofh.it> <JNoS5-bYOl-11@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Wed, Nov 27, 2024 at 12:55:10 +0100, tomas@tuxteam.de wrote:
> First: cd is not a command, it is a shell builtin
> (this is subtle, but important).
It's both. You can even call it a "builtin command".
> Second: even if cd were a "command", the splitting
> of args at whitespace (among *a lot* of other things)
> is done by the shell before the command has even a
> chance at it.
Yes. The shell *parses* each command you type, and among the steps
taken by the parser, one of the most basic is tokenizing the input
into words.
Given a command like this:
cd /mnt/c/Program Files
the tokenizer breaks it into words:
[cd] [/mnt/c/Program] [Files]
The first word will be the name of the command to run, and all the
words after that will be arguments passed to the command.
If you want "Program Files" to be treated as a single word, then you
must use quoting. There are several forms, and they're all acceptable:
cd "/mnt/c/Program Files"
cd '/mnt/c/Program Files'
cd /mnt/c/Program\ Files
cd /mnt/c/"Program Files"
In all four cases, the tokenizer only sees two words:
[cd] [/mnt/c/Program Files]
(A second parsing step is quote removal, which discards the quoting
characters that were used to aid the tokenization.)
Also just for the record, bash's tab completion feature is extremely
helpful. If you type just "cd /mnt/c/Pro" and then press the Tab key,
it will look at the actual file system and find files or directories
that match the current partial word. If there's only one match, then
it'll type out the rest of the filename for you. If there are multiple
matches, the behavior depends on your settings. You may need to press
Tab a second time to get a list of the matches, so that you can type
more characters to make your partial word have only a single match.
When tab completion auto-types a filename with whitespace in it, it'll
use the backslash quoting form to mark the spaces as literal characters
rather than word separators.
Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Using terminal commands - corner cases Richard Owlett <rowlett@access.net> - 2024-11-27 12:40 +0100
Re: Using terminal commands - corner cases <tomas@tuxteam.de> - 2024-11-27 13:00 +0100
Re: Using terminal commands - corner cases Richard Owlett <rowlett@access.net> - 2024-11-27 14:40 +0100
Re: Using terminal commands - corner cases <tomas@tuxteam.de> - 2024-11-27 14:40 +0100
Re: Using terminal commands - corner cases Richard Owlett <rowlett@access.net> - 2024-11-27 15:50 +0100
Re: Using terminal commands - corner cases Joe <joe@jretrading.com> - 2024-11-27 15:50 +0100
Re: Using terminal commands - corner cases Eric S Fraga <e.fraga@ucl.ac.uk> - 2024-11-27 15:20 +0100
Re: Using terminal commands - corner cases <tomas@tuxteam.de> - 2024-11-27 15:30 +0100
help, man, etc. (was Re: Using terminal commands - corner cases) The Wanderer <wanderer@fastmail.fm> - 2024-11-27 16:50 +0100
Re: help, man, etc. (was Re: Using terminal commands - corner cases) Greg Wooledge <greg@wooledge.org> - 2024-11-27 17:10 +0100
Re: help, man, etc. (was Re: Using terminal commands - corner cases) <tomas@tuxteam.de> - 2024-11-27 18:10 +0100
Re: help, man, etc. (was Re: Using terminal commands - corner cases) <tomas@tuxteam.de> - 2024-11-27 18:00 +0100
Re: help, man, etc. (was Re: Using terminal commands - corner cases) The Wanderer <wanderer@fastmail.fm> - 2024-11-27 18:30 +0100
Re: help, man, etc. (was Re: Using terminal commands - corner cases) <tomas@tuxteam.de> - 2024-11-27 18:50 +0100
Re: help, man, etc. (was: Re: Using terminal commands - corner cases) Max Nikulin <manikulin@gmail.com> - 2024-11-28 03:40 +0100
Re: help, man, etc. (was: Re: Using terminal commands - corner cases) <tomas@tuxteam.de> - 2024-11-28 06:40 +0100
Re: Using terminal commands - corner cases Yassine Chaouche <a.chaouche@algerian-radio.dz> - 2024-11-27 16:40 +0100
Re: Using terminal commands - corner cases Chris Green <cl@isbd.net> - 2024-11-27 17:20 +0100
Re: Using terminal commands - corner cases Greg Wooledge <greg@wooledge.org> - 2024-11-27 15:50 +0100
Re: Using terminal commands - corner cases David Wright <deblis@lionunicorn.co.uk> - 2024-11-28 05:20 +0100
Re: Using terminal commands - corner cases Richard Owlett <rowlett@access.net> - 2024-11-28 09:40 +0100
Re: Using terminal commands - corner cases Max Nikulin <manikulin@gmail.com> - 2024-11-28 16:00 +0100
Re: Using terminal commands - corner cases Richard Owlett <rowlett@access.net> - 2024-11-28 16:20 +0100
Re: Using terminal commands - corner cases Erwan David <erwan@rail.eu.org> - 2024-11-28 16:20 +0100
Re: Using terminal commands - corner cases David Wright <deblis@lionunicorn.co.uk> - 2024-11-29 19:40 +0100
Re: Using terminal commands - corner cases Max Nikulin <manikulin@gmail.com> - 2024-11-30 16:20 +0100
Re: Using terminal commands - corner cases David Wright <deblis@lionunicorn.co.uk> - 2024-12-02 04:00 +0100
Re: Using terminal commands - corner cases debian-user@howorth.org.uk - 2024-12-02 13:00 +0100
Re: Using terminal commands - corner cases Michael Paoli <michael.paoli@berkeley.edu> - 2024-12-02 10:20 +0100
csiph-web