Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 24 Oct 2017, 00:28
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
"O'Connor's Song" and aemenu (SOLVED)
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [7 Posts]  
Author Message
musher0


Joined: 04 Jan 2009
Posts: 10992
Location: Gatineau (Qc), Canada

PostPosted: Fri 18 Aug 2017, 18:11    Post subject:  "O'Connor's Song" and aemenu (SOLVED)
Subject description: Processing apostrophes and spaces one step removed.
 

Hello people.

I'm banging my head on this problem: can we process apostrophes AND
spaces at the same time in the same string?

My practical situation is as follows:

for the sake of argument, let's say I have a song, in ogg format, named
"O'Connor's Song". The file name is thus: OConnor's Song.ogg

I am trying to fit that as a line in aemenu. (Aemenu is a stand-alone
component of the aewm window manager.)

The structure of this menu has to be as follows:
cmd title executable

We can also have:
cmd "Longer Title" "executable some-parameter"

Back to my fictitious example, to incorporate O'Connor's Song in this
structure, I must use the form:
Code:
cmd "O'Connor's Song" "play O'Connor's Song.ogg"
(or mplayer instead of play, it doesn't matter).

I can solve the spaces problem by writing this:
Code:
cmd "O'Connor's Song" "play 'O'Connor's Song.ogg'"
Since the file name is between apostrophes, the spaces are interpreted ok.

This is where I am stumped. The piece will not play because there are
apostrophes in the parameter for the executable: "O'Connor's". Play does
not find the song, 'O', obviously, because I have used the apostrophe as
delimiter.

It's as if we cannot compensate for spaces AND apostrophes in the same
string at the same time.

If anyone can shed some light on this subject, I'll be grateful.

BFN.

_________________
musher0
~~~~~~~~~~
"Logical entities must not be multiplied beyond necessity." | |
« Il ne faut pas multiplier les entités logiques sans nécessité. » (Ockham)

Last edited by musher0 on Sat 19 Aug 2017, 04:00; edited 1 time in total
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 1639

PostPosted: Fri 18 Aug 2017, 18:32    Post subject:  

How about this?

Code:
# set cmd "O'Connor's Song" "play \"O'Connor's Song.ogg\""
#
# echo $1
cmd
# echo $2
O'Connor's Song
# echo $3
play "O'Connor's Song.ogg"
#

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
musher0


Joined: 04 Jan 2009
Posts: 10992
Location: Gatineau (Qc), Canada

PostPosted: Fri 18 Aug 2017, 19:36    Post subject:  

SFR wrote:
How about this?

Code:
# set cmd "O'Connor's Song" "play \"O'Connor's Song.ogg\""
#
# echo $1
cmd
# echo $2
O'Connor's Song
# echo $3
play "O'Connor's Song.ogg"
#

Greetings!

Hello SFR.

Thanks for responding.

Your solution will work at the console, but I have to construct the menu.

Perhaps I should have said it explicitly. That's what I meant by "one step
removed" in the sub-title.

The construction script has to contain:
Code:
> song-menu
echo "cmd \"O'Connor's Song\" \"play \"O'Connor's Song.ogg\"" >> song-menu

I cannot use \" three times in the executable part (2nd part), only two
times, otherwise nothing will play.

Also I do not understand your "echoes" $1, $2 and $3. In this
example, you are using a matrix, yes? Why separate when one needs
to concatenate?

I tried this:
Code:
set "cmd \"O'Connor's Song\" \"play \"O'Connor's Song.ogg\"\"";echo $1;echo $2;echo $3
Result is this:
Quote:
cmd "O'Connor's Song" "play "O'Connor's Song.ogg""
aemenu will stop reading after "play ".

Thanks in advance for any further explanation.

BFN.

_________________
musher0
~~~~~~~~~~
"Logical entities must not be multiplied beyond necessity." | |
« Il ne faut pas multiplier les entités logiques sans nécessité. » (Ockham)
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1372
Location: Japan

PostPosted: Fri 18 Aug 2017, 22:38    Post subject:  

Code:
echo "cmd \"O'Connor's Song\" \"play \\\"O'Connor's Song.ogg\\\"\""  >> song-menu

Result in song-menu:
Code:
cmd "O'Connor's Song" "play \"O'Connor's Song.ogg\""

Should work if your aemenu is able to pass the executable part correctly to the shell command interpreter.
Back to top
View user's profile Send private message 
musher0


Joined: 04 Jan 2009
Posts: 10992
Location: Gatineau (Qc), Canada

PostPosted: Sat 19 Aug 2017, 04:00    Post subject:  

The 3 escape characters ( "\\\" ) do the work! Thanks, MochiMoppei.

I'll mark this problem as solved.

Have a great day!
Spaces-&-apostrophes-2.jpg
 Description   
 Filesize   149.32 KB
 Viewed   92 Time(s)

Spaces-&-apostrophes-2.jpg


_________________
musher0
~~~~~~~~~~
"Logical entities must not be multiplied beyond necessity." | |
« Il ne faut pas multiplier les entités logiques sans nécessité. » (Ockham)
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 1639

PostPosted: Sat 19 Aug 2017, 10:01    Post subject:  

Quote:
Also I do not understand your "echoes" $1, $2 and $3. In this
example, you are using a matrix, yes? Why separate when one needs
to concatenate?

The 'set' and 'echos' were merely a demo to show what's the actual outcome of, mainly, this string:
Code:
"play \"O'Connor's Song.ogg\""

Could've just use 'echo', actually (it was late, nevermind Wink).

From what I see now, I overlooked the requirement of having the whole string (incl. 'play') wrapped in quotes, not only the filename.
Fortunately, Mochi provided the correct way.

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
musher0


Joined: 04 Jan 2009
Posts: 10992
Location: Gatineau (Qc), Canada

PostPosted: Sat 19 Aug 2017, 11:40    Post subject:  

Thanks for the explanation, SFR.

BFN.

_________________
musher0
~~~~~~~~~~
"Logical entities must not be multiplied beyond necessity." | |
« Il ne faut pas multiplier les entités logiques sans nécessité. » (Ockham)
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [7 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1345s ][ Queries: 12 (0.0259s) ][ GZIP on ]