Arthur Dessez Arthur Dessez - 1 year ago 133
Bash Question

System() parameters C

I've a problem with the


I want to create a little program which run a command x times.

The following code is to launch a command :

#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char *argv[])
char command[100];
strcpy(command, "(time lance REF_CLIENT_FOUR002542_C F > result.txt) 2> time.txt");
return 0;

My command is working when I write it directly in my shell, but when I use this program I get this error:

./lance: [[: introuvable
./lance: [[: introuvable
./lance: [[: introuvable
./lance: [[: introuvable
./lance: erreur de syntaxe ligne 34: `(' inattendue

This error means:

: not found

./lance: syntax error at line 34 : '
' unexpected

I guess that system try to execute my command like
time ./lance ...
, but I want to run this like a command not a program so time lance ...

I've already tried to run this program without the loop, still the same.

I've also tried a simpler command like
ls -l
; that's working.

If anyone can help me, I'll be very thankful!

Edit : My purpose is to run a script many time to have data about execution's time, that's why I wrote this program.

Edit2: This is a part of my script "lance" :

if [[ $# -ne 3 ]] # 1st not found
echo "bla"
exit 1

if [[ ! -f ${1} ]] # 2nd not found
echo "bla"
exit 1

if [[ ! -f ${2} ]] # 3rd not found
echo "bla"
exit 1

if [[ "${3}" != "F" && "${3}" != "Z" ]] #4th not found
echo "bla"
exit 1

if [[ -d TRAVAIL ]] # This is the line 34
mv TRAVAIL TRAVAIL_$(date +%d%m%y%H%M%S)

Edit3 : Thanks for alk who help me to find what was wrong is my code, I've added #!/bin/bash in the 1st line of my script and now it's working.

alk alk
Answer Source

./lance: syntax error at line 34 : '(' unexpected

In script lance on line 34 there is an unexpected ( character.

To debug the script put this

set -x

as first statement into the script.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download