Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #205971

[SOLVED II] (Thomas) Re: Bash file to variable string problem -- must be simple. What am I missing?

From deb <deb@rangingthoughts.org>
Newsgroups linux.debian.user
Subject [SOLVED II] (Thomas) Re: Bash file to variable string problem -- must be simple. What am I missing?
Date 2019-03-03 19:20 +0100
Message-ID <xxDSp-7xK-1@gated-at.bofh.it> (permalink)
References <xxrxU-8cu-3@gated-at.bofh.it> <xxu2L-1fB-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On 3/3/19 2:43 AM, Thomas Schmitt wrote:
> Hi,
>
> if spaces are involved, then quotation marks hould be put around the
> argument of "echo".
>
> Using the leading blank from David Wright's post:
>
>    $ fname=" long file with spaces.mp4"
>    $ x=`echo $fname | rev | cut -d. -f2 | rev`
>    $ test "$x".mp4 = "$fname" && echo IS EQUAL
>    $
>
> I.e. "$x".mp4 and "$fname" are not equal.
> That's because the leading blank got lost in the "echo" run:
>
>    $ echo "'$x'"
>    'long file with spaces'
>
> Now with quotation marks around $fname to preserve the leading blank:
>
>    $ x=`echo "$fname" | rev | cut -d. -f2 | rev`
>    $ test "$x".mp4 = "$fname" && echo IS EQUAL
>    IS EQUAL
>
> A similar effect would happen with double blanks inside the name:
>
>    $ fname="long file with  double  spaces.mp4"
>    $ x=`echo $fname | rev | cut -d. -f2 | rev`
>    $ echo "'$x'"
>    'long file with double spaces'
>    $ x=`echo "$fname" | rev | cut -d. -f2 | rev`
>    $ echo "'$x'"
>    'long file with  double  spaces'
>
>
> Have a nice day :)
>
> Thomas
>
>

Good thought Thomas!

This also worked:

   $ fname=`echo "$fname" | rev | cut -d. -f2

Now, the actual file did not have a leading (or trailing) space --- 
which I focused on.

But IT DID have 2 adjoining spaces Within the filename.

Enclosing $fname in "", worked perfectly.


That simple thing, that I thought I was missing, I would not have 
guessed at. Two adjoining spaces. :-)

*Thank you!*

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Bash file to variable string problem -- must be simple. What am I  missing? deb <deb@rangingthoughts.org> - 2019-03-03 02:00 +0100
  Re: Bash file to variable string problem -- must be simple. What am  I missing? Roberto C. Sánchez <roberto@debian.org> - 2019-03-03 02:10 +0100
    re: Bash file to variable string problem -- must be simple. What am I  missing? deb <deb@rangingthoughts.org> - 2019-03-03 03:50 +0100
      re: Bash file to variable string problem -- must be simple. What am  I missing? "der.hans" <deb-user@LuftHans.com> - 2019-03-03 04:40 +0100
        [SOLVED] Re: Bash file to variable string problem -- must be simple.  What am I missing? deb <deb@rangingthoughts.org> - 2019-03-03 16:10 +0100
      Re: Bash file to variable string problem -- must be simple. What am  I missing? David Wright <deblis@lionunicorn.co.uk> - 2019-03-03 06:10 +0100
        Re: Bash file to variable string problem -- must be simple. What am I missing? "Thomas Schmitt" <scdbackup@gmx.net> - 2019-03-03 08:50 +0100
          Re: Bash file to variable string problem -- must be simple. What am  I missing? David Wright <deblis@lionunicorn.co.uk> - 2019-03-03 16:40 +0100
            Re: Bash file to variable string problem -- must be simple. What am I missing? "Thomas Schmitt" <scdbackup@gmx.net> - 2019-03-03 18:50 +0100
            Greg: Re: Bash file to variable string problem -- must be simple.  What am I missing? deb <deb@rangingthoughts.org> - 2019-03-04 14:40 +0100
            Re: Bash file to variable string problem -- must be simple. What am  I missing? Greg Wooledge <wooledg@eeg.ccf.org> - 2019-03-04 14:40 +0100
          [SOLVED II] (Thomas) Re: Bash file to variable string problem -- must  be simple. What am I missing? deb <deb@rangingthoughts.org> - 2019-03-03 19:20 +0100
            Re: Bash file to variable string problem -- must be simple. What am I missing? "Thomas Schmitt" <scdbackup@gmx.net> - 2019-03-03 22:50 +0100
            Re: Bash file to variable string problem -- must be simple. What am  I missing? David Wright <deblis@lionunicorn.co.uk> - 2019-03-04 09:40 +0100
              David - Re: Bash file to variable string problem -- must be simple.  What am I missing? deb <deb@rangingthoughts.org> - 2019-03-04 15:10 +0100
                Re: David - Re: Bash file to variable string problem -- must be  simple. What am I missing? Greg Wooledge <wooledg@eeg.ccf.org> - 2019-03-04 15:40 +0100

csiph-web