1

I want to write a bash script that calls a compiled executable (I'm a beginning compsci student). However, I want to hide the actual file path from the call. Here's my function I have so far:

function comprun() 
{
   local source_file=$1
   local args=$2
   g++ -Wall -Wextra -Wconversion "$source_File" -o "$source_file.x";
   if [ $? -eq 0 ]; then
      echo -e "Running $source_file.x PARAM: $args\n==============\n";
      if [ -z "$args" ]; then
           ./$source_file.x;
      else
           ./$source_file.x $args;
      fi
   fi
}

This seems to work for what I want, save one issue: after the header you can see "Running...=====", it prints out the call of the executable. I'm not sure whether this is the fault of how I made it, or whether BASH doesn't hide file calls, but if it's the latter, is there a way I can hide it so it doesn't show as (say file is x.c with args 1 2):

Running x.c.x PARAM: 1 2
==========================
./x.c.x 1 2    

Any help is appreciated, thank you. I understand my other methods may be stupid or not work, but I'd prefer to fix those on my own if possible. For the moment this is my preoccupation. Thank you for any assistance.

NOTE: THIS IS NOT HOMEWORK. I'm just fiddling around with this, that's all.

1 Answer 1

0

Sorry. I didn't read my notes properly and it says right there: argv[0] == program name string. Hence, printf("%s %s %s\n", argv[0], argv[1], argv[2]);

Was technically doing exactly what I wanted it to. Thanks for offering this forum for questions, even as stupid as mine was :P

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .