From: calin <calin_cosma@mymail.ro>
To: linux-admin@vger.kernel.org
Subject: Re: Stupid spaces
Date: Wed, 21 Jul 2004 10:11:19 +0300 [thread overview]
Message-ID: <1090393856.3708.5.camel@LinuxMobile> (raw)
In-Reply-To: <16637.54479.400296.948283@cerise.nosuchdomain.co.uk>
Again, thank you all for your fast support.
I solved the problem. I somehow missed the double quotes and left them
in the wrong place.
So now work like this:
file_path='/some/where/Test Folder/'
echo "$file_path"
cd "$file_path"
On Wed, 2004-07-21 at 05:28, Glynn Clements wrote:
> Looking at this thread, quite a few people seem to have problems with
> shell quoting.
>
> As a general rule, literal values should be contained within single
> quotes, i.e.:
>
> file_path='/some/where/Test Folder/'
>
> while variable references should almost always be contained within
> double quotes:
>
> cd "$file_path"
>
> Within double quotes, variable expansions (e.g. $foo), command
> substitutions (e.g. `foo` or $(foo)), arithmetic substitutions (e.g.
> $[1+2] or $((1+2)) ) and similar (i.e. anything beginning with ` or $)
> are still evaluated, and the backslash character can be used to quote
> any of $ ` " \ or a newline.
>
> Within single quotes, everything up to the next single quote is taken
> literally (including the backslash character). If you need to include
> a single quote, use '\'', e.g.:
>
> $ echo 'it'\''s'
> it's
>
> [This parses as 'it' \' 's' (without the spaces), which the shell
> interprets is it ' s (again, without the spaces).]
>
> Unquoted variable expansions will subsequently be split into words so,
> as has already been noted, the commands:
>
> file_path='/some/where/Test Folder/'
> cd $file_path
>
> will result in the "cd" built-in command being called with two
> arguments, namely:
>
> /some/where/Test
> and:
> Folder/
>
> For this reason, variable references should usually be enclosed in
> double quotes; failure to do so is the main reason why scripts fail on
> filenames (or other arguments) which contain spaces.
>
> If you have trouble with shell syntax issues generally, it may help to
> compile and install the following program:
>
> #include <stdio.h>
>
> int main(int argc, char **argv)
> {
> int i;
> for (i = 0; i < argc; i++)
> printf("argv[%2d] = '%s'\n", i, argv[i]);
> return 0;
> }
>
> You can then use it to see exactly what the shell is doing with your
> command line before it gets to the program, e.g.:
>
> $ file_path='/some/where/Test Folder/'
> $ args $file_path
> argv[ 0] = '/usr/local/bin/args'
> argv[ 1] = '/some/where/Test'
> argv[ 2] = 'Folder/'
> $ args "$file_path"
> argv[ 0] = '/usr/local/bin/args'
> argv[ 1] = '/some/where/Test Folder/'
>
> It may also help to read the bash(1) manpage. OK, so it's a bit more
> than a "page" (I get 60 pages for 1.x, 86 pages for 2.x) but, if you
> use the command line regularly, you could easily spend hundreds of
> hours per year using bash.
---------------------------------------------------------------
Incearca acum noul sistem de dating oferit de portalul acasa.ro
next prev parent reply other threads:[~2004-07-21 7:11 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-19 13:29 Stupid spaces calin
2004-07-19 13:56 ` Chris DiTrani
2004-07-19 14:59 ` calin
2004-07-19 14:45 ` Scott Taylor
2004-07-19 14:52 ` Scott Taylor
2004-07-20 17:48 ` scohen
2004-07-20 18:22 ` Adam Lang
2004-07-20 17:55 ` scohen
2004-07-20 18:20 ` Chris DiTrani
2004-07-20 18:37 ` Adam Lang
2004-07-21 2:28 ` Glynn Clements
2004-07-21 7:11 ` calin [this message]
-- strict thread matches above, loose matches on Subject: below --
2004-02-13 19:13 urgrue
2004-02-12 21:08 Scott Taylor
2004-02-12 21:23 ` Alok K. Dhir
2004-02-12 22:19 ` Scott Taylor
2004-02-12 21:39 ` Yu Chen
2004-02-12 22:18 ` Scott Taylor
2004-02-13 2:15 ` rich+ml
2004-02-13 4:07 ` Emiliano Castagnari
2004-02-13 16:56 ` Scott Taylor
2004-02-13 6:51 ` Agus Budy Wuysang
2004-02-13 17:15 ` Scott Taylor
[not found] ` <Pine.LNX.4.44.0402121811240.3031-100000@deadrat.localdomai n>
2004-02-13 16:33 ` Scott Taylor
2004-02-13 17:26 ` rich+ml
[not found] ` <Pine.LNX.4.44.0402130907370.3031-100000@deadrat.localdomai n>
2004-02-13 17:33 ` Scott Taylor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1090393856.3708.5.camel@LinuxMobile \
--to=calin_cosma@mymail.ro \
--cc=linux-admin@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).