Sponsored Content
Top Forums Shell Programming and Scripting BASH arrays and variables of variables in C++ Post 302877448 by frad on Sunday 1st of December 2013 12:14:59 PM
Old 12-01-2013
We can embed bash code in C++ with the system command or the define shellscript approach. When the bash code is a bit more advanced, for examples arrays or evaluation of variables of variables, errors appear.

An example of what I want to do:

Var1=good
Var2=excellent

I wish to echo Var1 and Var2 by using a two variable approach $var and $k. var=Var is stable and index "k" increases. This can be easily done in Bash:

Code:
var=VAR
k=0
VAR0=good
VAR1=excellent

Code:
for ((k=0; k < 2 ;k++))
do
eval "echo "\$$var$k""
done

This bash script I wish to embed in C++
 

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
DEVSCRIPTS.CONF(5)						File Formats Manual						DEVSCRIPTS.CONF(5)

NAME
       devscripts.conf - configuration file for the devscripts package

DESCRIPTION
       The  devscripts	package provides a collection of scripts which may be of use to Debian developers and others wishing to build Debian pack-
       ages.  Many of these have options which can be configured on a system-wide and per-user basis.

       Every script in the devscripts package which makes use of values from these configuration files describes the specific settings	recognised
       in its own manpage.  (For a list of the scripts, either see /usr/share/doc/devscripts/README.gz or look at the output of dpkg -L devscripts
       | grep /usr/bin.)

       The two configuration files are /etc/devscripts.conf for system-wide defaults and ~/.devscripts for per-user settings.	They  are  written
       with  bash(1)  syntax, but should only have comments and simple variable assignments in them; they are both sourced (if present) by many of
       the devscripts scripts.	Variables corresponding to simple switches should have one of the values yes and no; any other setting is regarded
       as equivalent to the default setting.

       All  variable  names  are  written  in  uppercase, and begin with the script name.  Package-wide variables begin with "DEVSCRIPTS", and are
       listed below, as well as in the relevant manpages.

       For a list of  all  of  the  available  options	variables,  along  with  their	default  settings,  see  the  example  configuration  file
       /usr/share/doc/devscripts/devscripts.conf.ex.   This  is  copied  to  /etc/devscripts.conf  when the devscripts package is first installed.
       Information about configuration options introduced in newer versions of the package will be appended to /etc/devscripts.conf when the pack-
       age is upgraded.

       Every script which reads the configuration files can be forced to ignore them by using --no-conf as the first command-line option.

PACKAGE-WIDE VARIABLES
       The currently recognised package-wide variables are:

       DEVSCRIPTS_CHECK_DIRNAME_LEVEL, DEVSCRIPTS_CHECK_DIRNAME_REGEX
	      These  variables	control  scripts  which change directory to find a debian/changelog file or suchlike, and some other miscellaneous
	      cases.  In order to prevent unwanted, even possibly dangerous, behaviour, these variables control when actions  will  be	performed.
	      The scripts which currently make use of these variables are: debc, debchange/dch, debclean, debi, debrelease, debuild and uscan, but
	      this list may change with time (and I may not remember to update this manpage).  Please see the manpages of individual  scripts  for
	      details of the specific behaviour for each script.

SEE ALSO
       devscripts(1) and /usr/share/doc/devscripts/README.gz.

AUTHOR
       This manpage was written for the devscripts package by the package maintainer Julian Gilbey <jdg@debian.org>.

DEBIAN								 Debian Utilities						DEVSCRIPTS.CONF(5)
All times are GMT -4. The time now is 11:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy