Sponsored Content
Top Forums Shell Programming and Scripting BASH arrays and variables of variables in C++ Post 302877458 by Akshay Hegde on Sunday 1st of December 2013 01:28:06 PM
Old 12-01-2013
@ wisecracker I think following problem he is facing, in preprocessor directives


Code:
$ cat test.cpp

// working
#define SHELLSCRIPT1 "\
#/bin/bash \n\
echo \"hello\" \n\
"

// Not working
#define test1 "\
#/bin/bash \n\
array=(a1 a2 a3) \n \
echo ${array[*]} \n \
"

#include <iostream>
#include <cstdlib>
using namespace std;
int main ()
{
// working
cout <<system(SHELLSCRIPT1);

// whereas this is not working
cout <<system(test1);

return 0;
}

$ g++ test.cpp

$ ./a.out 
hello
sh: 2: Syntax error: "(" unexpected

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash variables

Ummm can anybody help me with this one? Its prob quite simple. I bascially have a file name say J1x2x3x7.dat Im using the file name as a variable in a bash script. Want I want to do is extract most of the file name and make it a new variable expect with say one of the number now a... (2 Replies)
Discussion started by: RichieFondel
2 Replies

2. Programming

How to convert byteArray variables to HexaString variables for Linux?

Hello everybody, I am having problem in converting byte array variables to Hexa String variables for Linux. I have done, converting byte array variables to Hexa String variables for Windows but same function doesn't work for linux. Is there any difference in OS ? The code for Windows is given... (2 Replies)
Discussion started by: ritesh_163
2 Replies

3. UNIX for Dummies Questions & Answers

Problem assigning variables to arrays

Hi All, I have a problem assigning variables to script.I have a script in which i have a while loop now i have to assign some values obtained to an array which will be used later in the script.Can anyone help how to do that. At present my scrot looks like: co=0 pco=0 co=`cat /tmp/highcpu... (4 Replies)
Discussion started by: usha rao
4 Replies

4. UNIX for Dummies Questions & Answers

awk arrays and variables

I have two arrays values aname = first aname = last I would like to assign a variable to both arrays seperated by a comma fname=(aname","aname) that example does not work but that's something I would like to accomplish. Is it possible to assign a printf output to a variable. ... (2 Replies)
Discussion started by: Morph797
2 Replies

5. UNIX for Dummies Questions & Answers

File Field Replacement, Assigning Fields to Variables, Lists/Arrays?

Okay, I've made threads on extracting fields and comparing strings in separate files in .csv's. I've written the following code with intentions of learning more. I just want this one question answered: How can I assign fields from a file(comma separated) to variables? My goal is to check... (0 Replies)
Discussion started by: chickeneaterguy
0 Replies

6. Shell Programming and Scripting

Creating variables in bash

I am writing some scripts using bash and am wondering if there is a better way to perform the following set of formatting variables. s1=" " s2=" " s3=" " s4=" " s5=" " s6=" " s7=" " s8=" " frmt_titl="${bYl}%s${nClor}\n" frmt1_titl="${s1}$frmt_titl"... (10 Replies)
Discussion started by: kristinu
10 Replies

7. Shell Programming and Scripting

functions and variables in bash

I have a bash script with some functions as below and am wondering if I can use the variables declared in setup in the other functions and in the rest of the bash script. setup(){ none=0; low=1; medium=2; high=3; debug=4 var1="red" var2="fred" } create_basemap() { ... (7 Replies)
Discussion started by: kristinu
7 Replies

8. Shell Programming and Scripting

Running a script with multiple variables like 25 variables.

Hi All, i have a requirement where i have to run a script with at least 25 arguements and position of arguements can also change. the unapropriate way is like below. can we achieve this in more good and precise way?? #!/bin/ksh ##script is sample.ksh age=$1 gender=$2 class=$3 . . .... (3 Replies)
Discussion started by: Lakshman_Gupta
3 Replies

9. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies
stdsyms(5)							File Formats Manual							stdsyms(5)

NAME
stdsyms - description of named defines and other specifications for namespace from HP-UX header files DESCRIPTION
is a description of "named defines" and other specifications that must be set by the application to obtain the appropriate namespace from the HP-UX header files. HP-UX header files are organized in a manner that allows for only a subset of the symbols available in that header file to be visible to an application that conforms to a specific standard. The ANSI-C, POSIX.1, POSIX.2, XPG4 and subsequent enhanced versions of ANSI-C/POSIX/XPG each reserve a certain set of symbols for that standard's namespace. In addition, the HP-UX implementation of XPG3 and the "OSF AES/OS" provides for a clean namespace although this is not a specific requirement of those standards. The following rules apply in determining what symbols are reserved for any standard. These symbols are reserved for the standard and for use by the implementation, and must be either avoided altogether, or used exactly as defined by the specified standard. o All symbols defined by the desired standard are reserved. Refer to the appropriate standards documentation for a complete list of reserved symbols. o All symbols beginning with an underscore followed by another underscore or an uppercase letter are reserved for the implementation. o All external identifiers beginning with an underscore are reserved for the implementation. The following is a list of feature test macros which must be defined to obtain the appropriate namespace from the header files. This symbol is automatically defined by the ANSI-C preprocessor and is automatically defined when specifying an ANSI-C compile Using the strict ANSI option requests a pure ANSI-C namespace, which is the smallest subset of the HP-UX namespace available. The option also enables the inclusion of ANSI-C-style function prototypes for increased type checking. Note that the default namespace when using the option is the ANSI-C namespace; therefore a broader namespace must be requested if it is desired. This symbol is automatically defined by the ANSI-C preprocessor on some implementations. If defined, it indicates the version of the standard it is complying with. As documented in the IEEE POSIX.1 standard, the programmer is required to define the feature test macro to obtain the POSIX.1 namespace and POSIX.1 functionality. This feature test macro can be defined, either by using compiler options or by using directives in the source files before any directives. Note that the default POSIX namespace is the POSIX.1-1990 namespace. It is necessary to define the feature test macro in addition to the macro in order to obtain the POSIX.1-1988 namespace. As documented in the IEEE POSIX.2 standard, the programmer is required to define the feature test macro with a value of 2 to obtain the POSIX.1 and POSIX.2 namespaces and functionality. This feature test macro can be defined, either by using compiler options or by using directives in the source files before any directives. As documented in the X/Open Portability Guide the programmer is required to define the feature test macro to obtain X/Open functionality. This feature test macro can be defined, either by using compiler options or by using directives in the source files before any directives. Although XPG3 does not specify any namespace pollution rules, XPG4 and its subsequent versions have instituted such rules. Therefore, the HP-UX operating system provides clean namespaces whenever is defined. The current default X/Open namespace is that corresponding to XPG4. Broader namespace can be requested by setting to a value as specified by the standard document. As documented in the XPG, the programmer is required to define the feature test macro to obtain namespace and functionality. This feature test macro can be defined either by using com- piler option or by using directives in the source files before any directives. As documented in the "OSF AES/OS" standard, the programmer is required to define the feature test macro to obtain OSF functionality. This feature test macro can be defined, either by using compiler options or by using directives in the source files before any directives. Although the AES does not specify any namespace pollution rules, the other standards have instituted such rules. Therefore HP-UX provides a clean names- pace whenever is defined. Use of is strongly discouraged as this functionality will be removed in a future release of HP-UX. The programmer can define the feature test macro to obtain the HP-UX namespace and complete HP-UX functionality. Note that the HP-UX namespace is currently a superset of all of the above mentioned namespaces. When using the compiler with default options or the compiler with compatibility- mode options command without the option), the HP-UX namespace is provided by default (see cc(1)). The programmer must request one of the other namespaces as described above to obtain the appropriate subset of the HP-UX namespace. When using the strict ANSI-C- mode compiler the programmer must specifically request a broader namespace. The feature test macro can be defined, either by using compiler options or by using directives in the source files before any direc- tives. The following is a list of miscellaneous feature test macros that provide various additional features. This symbol is automatically defined by the HP C++ compiler. Defining this macro enables the C++ function prototypes in system header files. The default namespace for HP C++ is the ANSI-C namespace. To obtain another namespace define the appropriate feature test macro. HP C++ uses the ANSI-C preprocessor by default. To get the compatibility mode preprocessor, use the option of the command (see cc(1)). The compatibility mode preprocessor uses the HP-UX namespace This feature test macro should be defined when the namespace is required. It should be used in conjunction with the macro if the default namespace is not desired. This macro is defined automatically whenever or is requested. The feature test macro is provided so that the programmer can obtain the XPG3 namespace, since it differs slightly from the namespace. In order to obtain the XPG3 namespace, the programmer must define both the and feature test macros. The and feature test macros can be defined, either by using compiler options or by using directives in the source files before any directives. Use of this macro is strongly discouraged as this functionality will be removed in a future release of HP-UX. The feature test macro is defined automatically if the programmer has requested the XPG4 namespace (that is, defined but not some other conflicting namespace such as The macro can be defined when using the compatibility mode compiler to obtain SVID2 function return types in the HP-UX namespace. The default return types of many functions have since been changed in the HP-UX operating system to align with the ANSI-C, POSIX, X/Open, and OSF standards. Use of this macro is strongly discouraged as this functionality will be removed in a future release of HP-UX. The SVID3 macro can be defined to obtain SVID3 function prototypes. The compiler flag, needs to be defined to indicate that an application is written to meet SVID3 requirements. At the time the func- tion prototypes were introduced in ANSI C, the functions exposed by this flag were only defined in SVID3. SEE ALSO
cc(1), cpp(1), pathconf(2), sysconf(2), standards(5). stdsyms(5)
All times are GMT -4. The time now is 09:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy