[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Display backslash-n in dialog?
From: |
Michael D. Setzer II |
Subject: |
Re: Display backslash-n in dialog? |
Date: |
Tue, 26 Jul 2011 09:51:16 +1000 |
On 25 Jul 2011 at 12:55, Moray Henderson wrote:
From: Moray Henderson <address@hidden>
To: <address@hidden>
Subject: Display backslash-n in dialog?
Date sent: Mon, 25 Jul 2011 12:55:18 +0100
>
> Hi,
>
> Is there a nice way to display the literal sequence `\n´ in dialog? I'm
> writing a
> confirmation box for deleting a set of directories from a Windows
> perspective:
>
> dialog --yesno "This will delete:\n - I:\\$CHOICE\n -
> P:\\$CHOICE\nContinue?" 8 40
>
> It works perfectly until the directory name in $CHOICE begins with `n´.
> The best I have
> been able to come up with is to separate the backslash and $CHOICE with a
> space-
> backspace sequence:
>
> dialog --yesno $'This will delete:\n - I:\\ \b'"$CHOICE"$'\n - P:\\
> \b'"$CHOICE"$'\nContinue?' 8 40
>
> It works after a fashion, but the code is ugly and so is the output:
>
> dialog.png
>
> I´m using CentOS 5.6, dialog Version: 1.0-20051107, writing a program to
> help manage
> Samba services (hence the need for Windows-style paths).
>
>
> Moray.
> "To err is human; to purr, feline."
>
>
>
You didn't mention if the path would only have one subdirectory or
might have multiple \n possibilities.
I came up with this that seems to work in some ways. The choice5
combines all the options in one.
Choice2 just changes the /'s to \'s to avoid the problem, but might
confuse windows users?
Choice3 would uses the color option to get ride to the \n issue.
CHOICE="new\new"
CHOICE2=`echo /$CHOICE |tr '\' '/'`
CHOICE3=`echo $CHOICE2 | sed -e 's:/n://Z0n:g'`
CHOICE4=`echo $CHOICE3 |tr '/' '\'`
CHOICE5=`echo /$CHOICE |tr '\' '/' | sed -e 's:/n://Z0n:g' |tr '/' '\' `
dialog --yesno "This will delete:\n - I:$CHOICE2\n -
P:$CHOICE2\nContinue?" 8 40
dialog --yesno $'This will delete:\n - I:\\ \b'"$CHOICE"$'\n - P:\\
\b'"$CHOICE"$'\nContinue?' 8 40
dialog --colors --yesno "This will delete:\n - I:\\\Z0$CHOICE\Z0\n -
P:\\\Z0$CHOICE\Z0\nContinue?" 8 40
dialog --colors --yesno "This will delete:\n - I:$CHOICE4\n -
P:$CHOICE4\nContinue?" 8 40
dialog --colors --yesno "This will delete:\n - I:$CHOICE5\n -
P:$CHOICE5\nContinue?" 8 40
+----------------------------------------------------------+
Michael D. Setzer II - Computer Science Instructor
Guam Community College Computer Center
mailto:address@hidden
mailto:address@hidden
http://www.guam.net/home/mikes
Guam - Where America's Day Begins
G4L Disk Imaging Project maintainer
http://sourceforge.net/projects/g4l/
+----------------------------------------------------------+
http://setiathome.berkeley.edu (Original)
Number of Seti Units Returned: 19,471
Processing time: 32 years, 290 days, 12 hours, 58 minutes
(Total Hours: 287,489)
address@hidden CREDITS
SETI 11044762.090437 | EINSTEIN 6244118.820851
ROSETTA 3419559.179626 | ABC 7086091.917007