LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-07-2011, 03:04 PM   #1
john_erlandsson
Member
 
Registered: Jul 2009
Location: Sweden
Distribution: Fedora
Posts: 70

Rep: Reputation: 1
[SOLVED]Bash script single quote question


Hi!

I am trying to incorporate a gimp batch script into a bash script.

The gimp command have to use single quotes
Example:
Code:
gimp -i -b '(my-script "script-argument")' -b '(gimp-quit 0)'
It does not accept double quotes.

The problem is that i need to pass a bash variable as an argument to my gimp function.

I tried this:
Code:
gimpcmd="gimp -i -b '(batch-coelipse \"$filename\")' -b '(gimp-quit 0)'"
($gimpcmd)
But it throws an error as if the end of the variable $filename ended with a )

I also played around with it on the command line. It works if I echo the $gimpcmd, copy the output and run it as a command. But it fails if I try too run $gimpcmd as a command.

Does anyone know how to throw a variable in between two single quotes in a bash script?

//John

Last edited by john_erlandsson; 07-07-2011 at 03:48 PM.
 
Old 07-07-2011, 03:19 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978Reputation: 1978
What about closing the single quotes immediately before the $filename variable?
Code:
gimp -i -b 'my-script '\"$filename\" -b '(gimp-quit 0)'
 
Old 07-07-2011, 03:26 PM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Probably the gimp command doesn't need single quotes but it needs to be made up of separate words:
  1. gimp
  2. -i
  3. -b
  4. (my-script file-name)
  5. -b
  6. (gimp-quit 0)
On the command line, enclosing (my-script file-name) in single quotes makes bash pass it to gimp as a single word.

Probably your script builds the command OK but when you try to run it as $gimpcmd (the enclosing () simply run it in a subshell), bash separates it into words at metacharacters which include "(", ")" and space.

What you are trying to do is difficult in bash. For your command it could probably be done by loading an array with individual words of the array providing the file name does not contain whitespace:
Code:
command[1]=gimp
...
command[4]="(my-script $file_name)")
...
"${command[@]}"
EDIT: hello colucix

Last edited by catkin; 07-07-2011 at 03:27 PM. Reason: removed OP quote
 
1 members found this post helpful.
Old 07-07-2011, 03:32 PM   #4
john_erlandsson
Member
 
Registered: Jul 2009
Location: Sweden
Distribution: Fedora
Posts: 70

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by colucix View Post
What about closing the single quotes immediately before the $filename variable?
Code:
gimp -i -b 'my-script '\"$filename\" -b '(gimp-quit 0)'
That does not seem to work. But thanks for taking an interest.

//John
 
Old 07-07-2011, 03:44 PM   #5
john_erlandsson
Member
 
Registered: Jul 2009
Location: Sweden
Distribution: Fedora
Posts: 70

Original Poster
Rep: Reputation: 1
Code:
gimpcmd[1]=gimp
gimpcmd[2]=-i
gimpcmd[3]=-b
gimpcmd[4]="(batch-coelipse \"$filename\")"
gimpcmd[5]=-b
gimpcmd[6]="(gimp-quit 0)"
"${gimpcmd[@]}"
WORKS!

Thank you very much!
 
  


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] How to pass a single quote inside of a single quote... trist007 Linux - Newbie 2 02-09-2011 07:07 PM
[SOLVED] Script to remove single quote that begin and end file names SteveInTallyFL Programming 6 08-16-2010 09:31 AM
[SOLVED] escaping a single quote from a bash script atbrew Programming 8 07-21-2010 09:21 AM
how to use single quote in bash shell like: echo ''\''' linuxtyh Linux - General 6 12-11-2008 11:56 PM
Double and single quote, Question in expect evilchild Programming 4 08-22-2004 05:34 PM


All times are GMT -5. The time now is 06:20 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration