In your modified example, I don't see that you would execute load.sh anywhere. What effect would you like to see? Please provide a complete transscript, showing what you are doing.
In your modified example, I don't see that you would execute load.sh anywhere. What effect would you like to see? Please provide a complete transscript, showing what you are doing.
The example in post #9 works, it has all the files in one directory.
A C++ function main(), returns an error code (1 means EXIT_FAILURE).
The error code is passed from the main() function, to load.sh, to test.sh.
And then test.sh uses the returned error code in a conditional statement.
The following example is similar, but with load.sh script in a different directory.
The files where copied from the example in post #9, and the relative paths updated.
But the output is not as expected, and Bash is not printing any error messages.
The following is a listing of the files with the new relative paths, followed by output.
$ cat tests.sh with new relative path:
Code:
#!/bin/bash
if test ../tut0/load.sh
then
echo "0"
else
echo "1"
fi
$ cat ../tut0/load.sh with new relative path:
Code:
#!/bin/bash
../suite/main
rc=$?
echo $rc
exit $rc
$ cat main.cpp:
Code:
int main()
{
return 1; //EXIT_FAILURE
}
From the terminal:
Code:
$ g++ main.cpp -o main
$ ./tests.sh
0
I was expecting it to output "1" twice, as in post #9.
A top view of the directory structure:
Code:
$ cd ..
$ ls
suite tut0 tut1
$ ls suite
load.sh main main.cpp~ tests.sh
load.sh~ main.cpp tests.sh~
$ ls tut0
load.sh load.sh~
What is the proper way to specify a relative path in bash?
For debug purposes, you might want to pwd in each and every script, and also ls the relevant paths/scripts.
Good idea. The pwd and ls outputs are as expected. But load.sh never gets called.
Why is load.sh not called?
$ cat tests.sh
Code:
#!/bin/bash
echo "in tests.sh --------"
echo "pwd:"
pwd
echo "ls:"
ls
echo "ls ../tut0:"
ls ../tut0
echo "load.sh returned:"
if test ../tut0/load.sh
then
echo "0"
else
echo "1"
fi
$ cat ../tut0/load.sh
Code:
#!/bin/bash
echo "in load.sh --------"
echo "pwd:"
pwd
echo "ls:"
ls
ls "ls ../suite:"
ls ../suite
../suite/main
rc=$?
echo "rc:"
echo $rc
exit $rc
From the terminal:
Code:
$ ./tests.sh
in tests.sh --------
pwd:
/home/wolfv/Documents/developer/c++/demo/test_script/suite
ls:
load.sh load.sh~ main main.cpp main.cpp~ tests.sh tests.sh~
ls ../tut0:
load.sh load.sh~
load.sh returned:
0
I was expecting output to also contain the line "in load.sh --------".
Hi All,
Good Day, seeking for your assistance on how to not perform my 2nd, 3rd,4th etc.. function if my 1st function is in else condition.
#Body
function1()
{
if
then
echo "exist"
else
echo "not exist"
}
#if not exist in function1 my all other function will not proceed.... (4 Replies)
Heyas,
Since this question (similar) occur every now and then, and given the fact i was thinking about it just recently (1-2 weeks) anyway, i started to write something :p
The last point for motivation was... (17 Replies)
Hi All,
I am using malloc function for allocating dynamic memory.
When I am using below code on Linux server its working fine, but When I am trying the same code on HP UNIX server its returning NULL.
below is a fragment of code in which it is giving problem.
tmp = (format_tree... (4 Replies)
Hi searched hi and wide for this with no luck.
Maintaining a bash script that
#!/usr/bin/bash
#does some stuff like setting env etc.
f_do_dbwork
...
..
#Now I want to exit with the value of $err however $err is re-initialised to 0 on exiting the function
Always 0
....
... (3 Replies)
Hi All
In my script, I can call on several functions. I have a logging function that is called by any of these functions. What I would like is some way of identifying which function I am using and pass this to the log function as some parameter.
Is there some built in command or way of... (3 Replies)
Hello all,
I would like to know if it is possible to return a the result of a boolean expression from a function like this
function()
{
# some code
return ||
}
and what will be the return value ?
Thank you for help. (6 Replies)
hi
how can I return multiple values from a C function. I tried the following:
#include <stdio.h>
void foo(int id, char *first_name, char *last_name)
{
/*
this is just an example to illustrate my problem... real code makes
use of the "id" parameter.
*/
first_name = (char... (8 Replies)
Hi all,
I am very new to BASH shell programming. I need to return an integer from a function to the caller function. I did this:
but it keeps giving me wrong return:
Can someone help me out here, please?
Thanks (2 Replies)
I have two string returning function in ESQL/C
char *segment_name(lbuffer)
char *lbuffer;
{.....
and
char *get_bpdvalue(f_name)
char *f_name;
{......
both declared above main()
char *get_bpdvalue();
char *segment_name();
my problem is segment_name works on sprintf and strcpy... (5 Replies)