LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-09-2010, 09:36 PM   #1
bvkim
LQ Newbie
 
Registered: Apr 2010
Posts: 23

Rep: Reputation: 15
Run a C program from bash script


I'm trying to write a bash script that helps me building C program then run the C program but I don't know how to make it run.
I did like this

Code:
#!/bin/sh

# assuming I've built C program '$output' successfully

# then call C program from script
`./$output` # error here, "command not found"
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 05-09-2010, 10:28 PM   #2
ArfaSmif
Member
 
Registered: Oct 2008
Location: Brisbane Australia
Distribution: Fedora, Centos, Manjaro
Posts: 317

Rep: Reputation: 70
Quote:
Originally Posted by bvkim View Post
I'm trying to write a bash script that helps me building C program then run the C program but I don't know how to make it run.
I did like this

Code:
#!/bin/sh

# assuming I've built C program '$output' successfully

# then call C program from script
`./$output` # error here, "command not found"
Code:
#!/bin/sh

output
This will work if output is executable and also in your PATH variable. Otherwise, simply put the full pathname to output in your script, for example /home/user/bin/output (it still has to be executable though.
 
Old 05-09-2010, 11:20 PM   #3
bvkim
LQ Newbie
 
Registered: Apr 2010
Posts: 23

Original Poster
Rep: Reputation: 15
@ArfaSmif:
still error

Code:
# Testing output
execute="."`pwd`"/$output"
echo "$execute" # full path name correct
$(execute) # error: execute: command not found
execute # error: execute: command not found
 
Old 05-09-2010, 11:23 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
echo is a command.
$execute is a variable.

Try maybe - eval "$execute"
 
2 members found this post helpful.
Old 05-10-2010, 12:02 AM   #5
bvkim
LQ Newbie
 
Registered: Apr 2010
Posts: 23

Original Poster
Rep: Reputation: 15
Thumbs up

Quote:
Originally Posted by grail View Post
echo is a command.
$execute is a variable.

Try maybe - eval "$execute"
Thanks, eval() is what i'm looking for.
Problem solved!
 
Old 05-10-2010, 12:35 AM   #6
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
bvkim -

As a courtesy, please be sure to:
a) thank grail (the blue "thumbs up" icon)
... and ...
b) mark your thread "solved" (makes it easier for other folks with the same problem to find your question, and the corresponding solution)

Thank you in advance .. PSM
 
  


Reply



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
My BASH script work perfect when i run it manualy, but not when it run in the crontab roqarg Linux - Newbie 30 05-06-2010 01:37 PM
Bash Script Help - Trying to create a variable inside script when run. webaccounts Linux - Newbie 1 06-09-2008 02:40 PM
how to run one bash script from within another? babag Programming 9 04-28-2005 12:12 AM
How can I get the computer to boot up and run a program/game w/ bash script or C++? DaMan101 Programming 5 04-11-2004 03:22 PM
How can I get the computer to boot up and run a program/game w/ bash script or C++? DaMan101 Linux From Scratch 1 04-10-2004 12:23 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:35 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