LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-10-2009, 01:49 PM   #1
musonio
Member
 
Registered: Jun 2009
Distribution: PCLinuxOS
Posts: 33

Rep: Reputation: 15
[SOLVED] Question about bash script syntax


I'm starting to learn bash scripting and I can't figure oput what's wrong with the following.

Code:
#!/bin/bash -x
ALFA=`kdesu "kdialog --getexistingdirectory ."`
echo $ALFA

Last edited by musonio; 09-10-2009 at 07:29 PM. Reason: SOLVED
 
Old 09-10-2009, 02:02 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
There's a clue in what you get back when you run the embedded command at the command prompt
Code:
kdesu "kdialog --getexistingdirectory ."
The problem is probably (I don't know kdesu) that it is getting a single argument, "kdialog --getexistingdirectory ." and probably wants three: kdialog, --getexistingdirectory, and

Try removing the double quotes.
 
Old 09-10-2009, 02:04 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982
Well. The syntax is absolutely correct. I can only suggest to use the $(command) notation for command substitution in bash. Instead, the logic of your code is obscure to me.

You're trying to run a graphical application and assign its output to the variable ALFA using command substitution, but... what output? The command kdesu kdialog etc. will prompt you for root password, then it let you choose a directory from a window. That's it.

Maybe if you describe what you're trying to accomplish or what do you expect in the value of the variable ALFA, we can be more helpful!
 
Old 09-10-2009, 02:42 PM   #4
musonio
Member
 
Registered: Jun 2009
Distribution: PCLinuxOS
Posts: 33

Original Poster
Rep: Reputation: 15
Damn that was fast! I didn't expect an answer for a couple of weeks.
Thanks for that.
I'm trying to mount a usb stick (in the middle of a user script) in a directory under /mnt:

Code:
#!/bin/bash -x

MOUNT_DIR=`kdesu "kdialog --getexistingdirectory /mnt"`

if [ ! -e $MOUNT_DIR ]; then
	kdesu "mkdir $MOUNT_DIR"
fi

MOUNT_TYPE=`kdialog --radiolist "Tipo:" 1 "vfat" off 2 "ext3" on`

if [ $MOUNT_TYPE = 1 ]; then
	kdesu "mount -t vfat /dev/sdc $MOUNT_DIR -o loop"
elif [ $MOUNT_TYPE = 2 ];then
	kdesu "mount -t ext3 /dev/sdc $MOUNT_DIR  -o loop"
fi
I know it seems like I'm taking the wrong way to do something otherwise simple, but it will serve, at least, the purpose of learning.
 
Old 09-10-2009, 02:47 PM   #5
musonio
Member
 
Registered: Jun 2009
Distribution: PCLinuxOS
Posts: 33

Original Poster
Rep: Reputation: 15
colucix:
You are right about the fact that I was wrongly assuming that kdesu would give me an oputput that it can't possibly give me.
The question is, then how to get that value?

Last edited by musonio; 09-10-2009 at 03:23 PM.
 
Old 09-10-2009, 04:17 PM   #6
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 404Reputation: 404Reputation: 404Reputation: 404Reputation: 404
Erm, it's not the output of kdesu which you want, but the output of kdialog
 
Old 09-10-2009, 04:47 PM   #7
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982
Quote:
Originally Posted by musonio View Post
Damn that was fast! I didn't expect an answer for a couple of weeks.
Thanks for that.
He he he... Welcome to LinuxQuestions!
 
Old 09-10-2009, 04:54 PM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982Reputation: 1982
Quote:
Originally Posted by i92guboj View Post
Erm, it's not the output of kdesu which you want, but the output of kdialog
i92guboj, you hit the nail on the head!
 
Old 09-10-2009, 06:46 PM   #9
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 355

Rep: Reputation: 165Reputation: 165
According to 'kdesu --help' adding '-t' to kdesu will "Enable terminal output" and this seems to be needed to make your code work.
'2>/dev/null' stops some messages from stderr being put into the variable 'MOUNT_DIR' along with the directory name.
Try
Code:
MOUNT_DIR=`kdesu -t "kdialog --getexistingdirectory /mnt 2>/dev/null"`
 
Old 09-10-2009, 07:28 PM   #10
musonio
Member
 
Registered: Jun 2009
Distribution: PCLinuxOS
Posts: 33

Original Poster
Rep: Reputation: 15
OH you wonderful people!!!!
Instead of telling me to RTFM, you provide me with the simplest solution.
catkin's reply lets me mark it as SOLVED SOLVED SOLVED.

With great knowledge comes the chance to help ignorant bastards like myself.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Question about sed syntax in bash script musonio Linux - Software 2 08-21-2009 07:17 AM
SED in BASH Script - Syntax Problem stlouis Programming 4 01-13-2008 10:38 AM
Bash script syntax error snowman81 Programming 5 11-16-2007 02:35 AM
How to check the bash script syntax? mesh2005 Linux - General 2 04-23-2006 08:22 AM
help with basic syntax in bash script Supp0rtLinux Linux - Software 4 03-27-2003 06:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration