Sponsored Content
Full Discussion: Add value to end of array
Top Forums Shell Programming and Scripting Add value to end of array Post 302753317 by Corona688 on Tuesday 8th of January 2013 11:28:04 AM
Old 01-08-2013
That arrays make loops such a pain is one reason I think they're overused.

Code:
A1="a b c d e f g"
A2=" q i u d e f g"

for X in $A1
do
        FOUND=0

        for Y in $A2
        do
                [ "$X" = "$Y" ] && FOUND=1
                [ "$FOUND" -gt 0 ] && break
        done

        [ "$FOUND" -eq 0 ] && A1="$A1 $X"
done

But if you must use arrays, that kind of loop works with them too:

Code:
for X in "${A1[@]}"
do
        FOUND=0

        for Y in "${A2[@]}"
        do
                [ "$X" = "$Y" ] && FOUND=1
                [ "$FOUND" -gt 0 ] && break
        done

        [ "$FOUND" -eq 0 ] && A1=( "${A1[@]}" $X )
done

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add a comma at end of every line

hello A small shell scripting help.. I have a file say with 5 lines of text (text file). At the end of everyline I need to add a comma at the end of the file. Thanks, ST2000 (4 Replies)
Discussion started by: ST2000
4 Replies

2. Shell Programming and Scripting

Add a new end of line

Hi, Does anyone know if its possible to add something like an end of line like c or java in unix? dirs=/home/nosnam var='' for dir in $dirs do listDirs=`ls -d1 $dir/*` for eachList in $listDirs do listRepos=`du -ks $eachList | awk '{ x+=$1 }; END { print x... (4 Replies)
Discussion started by: nosnam
4 Replies

3. Shell Programming and Scripting

array access in END block failure

Hi guys i am new to shell scripting. I wrote this script that simply searches a column value of file1 from file2. please look at the code below: awk ' FILENAME==ARGV { file_1_data=$0; next } FILENAME==ARGV { file_2_data=substr($3,1,12); next } END { ... (5 Replies)
Discussion started by: fahadaizaz
5 Replies

4. Shell Programming and Scripting

Accessing single elements of a awk array in END

How do I access one of the indices in array tst with the code below? tst=sprintf("%5.2f",Car / 12) When I scan thru the array with for ( i in tst ) { print i,tst } I get the output of: vec-7 144 But when I try this in the END print tst It looks like it's not set. What am... (6 Replies)
Discussion started by: timj123
6 Replies

5. Shell Programming and Scripting

Add end of char \n on end of file

Hi, I want to add \n as a EOF at the end of file if it does't exist in a single command. How to do this? when I use command echo "1\n" > a.txt and od -c a.txt 0000000 1 \n \n 0000003 How does it differentiate \n and eof in this case? Regards, Venkat (1 Reply)
Discussion started by: svenkatareddy
1 Replies

6. Shell Programming and Scripting

To add a number at the end of the line

Hi Folks, Using the Vi, how can I add a numbers at the end of the line. For eg: I have the numbers in the file as: 58.125.33 22.58.68 25.144.225 114.25.38 I need to add .0/8 at the end of all the line. So, it should be like 58.125.33.0/8 22.58.68.0/8 25.144.225.0/8 114.25.38.0/8 (6 Replies)
Discussion started by: gsiva
6 Replies

7. Shell Programming and Scripting

how to add ; at the end of last line

hi, i have file which is having large sql query eg : i am executing this sql file but now i want to add ; after query on same line i.e. i should look like any idea how to achieve it ? (6 Replies)
Discussion started by: crackthehit007
6 Replies

8. Shell Programming and Scripting

Add line at the end

How to add a comma at the end of each line in this file?30 1412 30 3352 30 5254 30 5543 30 7478 3 28 3 30 3 39 3 54 3 108 3 152 3 178 3 182 3 214 3 271 3 286 3 300 3 348 3 349 3 371 (3 Replies)
Discussion started by: gunjan
3 Replies

9. Shell Programming and Scripting

Add a new field at the end of each line

i want to add a white-space at the end of each line for my inp.file, but when i do it, the result is a new line with a white-space between each line! my input: 2012 0811 1223 15.2 L 38.393 46.806 9.0 Teh 78 0.5 6.5LTeh 1 GAP=74 ... (5 Replies)
Discussion started by: saeed.soltani
5 Replies

10. Shell Programming and Scripting

Add text to the end of line

Seems simple but ive been searching for a good hour of so I have a text file and would like to add a string to the end of line 5 ( as an example) to ake tings hard the line number we have to add the text to is stored in a variable cunningly name $Line_to_append any ideas on how this could... (2 Replies)
Discussion started by: dunryc
2 Replies
pkg-config(1)						      General Commands Manual						     pkg-config(1)

NAME
pkg-config - Return metainformation about installed libraries SYNOPSIS
pkg-config [--modversion] [--help] [--print-errors] [--silence-errors] [--cflags] [--libs] [--libs-only-L] [--libs-only-l] [--cflags-only- I] [--variable=VARIABLENAME] [--define-variable=VARIABLENAME=VARIABLEVALUE] [--uninstalled] [--exists] [--atleast-version=VERSION] [--exact-version=VERSION] [--max-version=VERSION] [LIBRARIES...] DESCRIPTION
The pkg-config program is used to retrieve information about installed libraries in the system. It is typically used to compile and link against one or more libraries. Here is a typical usage scenario in a Makefile: program: program.c cc program.c `pkg-config --cflags --libs gnomeui` pkg-config retrieves information about packages from special metadata files. These files are named after the package, with the extension .pc. By default, pkg-config looks in the directory prefix/lib/pkgconfig for these files; it will also look in the colon-separated (on Win- dows, semicolon-separated) list of directories specified by the PKG_CONFIG_PATH environment variable. The package name specified on the pkg-config command line is defined to be the name of the metadata file, minus the .pc extension. If a library can install multiple versions simultaneously, it must give each version its own name (for example, GTK 1.2 might have the package name "gtk+" while GTK 2.0 has "gtk+-2.0"). OPTIONS
The following options are supported: --modversion Requests that the version information of the libraries specified on the command line be displayed. If pkg-config can find all the libraries on the command line, each library's version string is printed to stdout, one version per line. In this case pkg-config exits successfully. If one or more libraries is unknown, pkg-config exits with a nonzero code, and the contents of stdout are unde- fined. --help Displays a help message and terminates. --print-errors If one or more of the modules on the command line, or their dependencies, are not found, or if an error occurs in parsing a .pc file, then this option will cause errors explaining the problem to be printed. With "predicate" options such as "--exists" pkg-con- fig runs silently by default, because it's usually used in scripts that want to control what's output. This option can be used alone (to just print errors encountered locating modules on the command line) or with other options. The PKG_CONFIG_DEBUG_SPEW environment variable overrides this option. --silence-errors If one or more of the modules on the command line, or their dependencies, are not found, or if an error occurs in parsing a a .pc file, then this option will keep errors explaining the problem from being printed. With "predicate" options such as "--exists" pkg- config runs silently by default, because it's usually used in scripts that want to control what's output. So this option is only useful with options such as "--cflags" or "--modversion" that print errors by default. The PKG_CONFIG_DEBUG_SPEW environment vari- able overrides this option. --errors-to-stdout If printing errors, print them to stdout rather than the default stderr The following options are used to compile and link programs: --cflags This prints pre-processor and compile flags required to compile the packages on the command line, including flags for all their dependencies. Flags are "compressed" so that each identical flag appears only once. pkg-config exits with a nonzero code if it can't find metadata for one or more of the packages on the command line. --libs This option is identical to "--cflags", only it prints the link flags. As with "--cflags", duplicate flags are merged (maintaining proper ordering), and flags for dependencies are included in the output. --libs-only-L This prints the -L/-R part of "--libs". That is, it defines the library search path but doesn't specify which libraries to link with. --libs-only-l This prints the -l part of "--libs" for the libraries specified on the command line. Note that the union of "--libs-only-l" and "--libs-only-L" may be smaller than "--libs", due to flags such as -rdynamic. --variable=VARIABLENAME This returns the value of a variable defined in a package's .pc file. Most packages define the variable "prefix", for example, so you can say: $ pkg-config --variable=prefix glib-2.0 /usr/ --define-variable=VARIABLENAME=VARIABLEVALUE This sets a global value for a variable, overriding the value in any .pc files. Most packages define the variable "prefix", for example, so you can say: $ pkg-config --print-errors --define-variable=prefix=/foo --variable=prefix glib-2.0 /foo --uninstalled Normally if you request the package "foo" and the package "foo-uninstalled" exists, pkg-config will prefer the "-uninstalled" vari- ant. This allows compilation/linking against uninstalled packages. If you specify the "--uninstalled" option, pkg-config will return successfully if any "-uninstalled" packages are being used, and return failure (false) otherwise. (The "PKG_CONFIG_DISABLE_UNIN- STALLED" environment variable keeps pkg-config from implicitly choosing "-uninstalled" packages, so if that variable is set, they will only have been used if you pass a name like "foo-uninstalled" on the command line explicitly.) --exists --atleast-version=VERSION --exact-version=VERSION --max-version=VERSION These options test whether the package or list of packages on the command line are known to pkg-config, and optionally whether the version number of a package meets certain contraints. If all packages exist and meet the specified version constraints, pkg-config exits successfully. Otherwise it exits unsuccessfully. Rather than using the version-test options, you can simply give a version constraint after each package name, for example: $ pkg-config --exists 'glib-2.0 >= 1.3.4 libxml = 1.8.3' Remember to use --print-errors if you want error messages. --msvc-syntax This option is available only on Windows. It causes pkg-config to output -l and -L flags in the form recognized by the Microsoft Visual C++ command-line compiler, cl. Specifically, instead of -Lx:/some/path it prints /libpath:x/some/path, and instead of -lfoo it prints foo.lib. Note that the --libs output consists of flags for the linker, and should be placed on the cl command line after a /link switch. --dont-define-prefix This option is available only on Windows. It prevents pkg-config from automatically trying to override the value of the variable "prefix" in each .pc file. --prefix-variable=PREFIX Also this option is available only on Windows. It sets the name of the variable that pkg-config automatically sets as described above. --static Output libraries suitable for static linking. That means including any private libraries in the output. This relies on proper tag- ging in the .pc files, else a too large number of libraries will ordinarily be output. ENVIRONMENT VARIABLES
PKG_CONFIG_PATH A colon-separated (on Windows, semicolon-separated) list of directories to search for .pc files. The default directory will always be searched after searching the path; the default is libdir/pkgconfig:datadir/pkgconfig where libdir is the libdir where pkg-config and datadir is the datadir where pkg-config was installed. PKG_CONFIG_DEBUG_SPEW If set, causes pkg-config to print all kinds of debugging information and report all errors. PKG_CONFIG_TOP_BUILD_DIR A value to set for the magic variable pc_top_builddir which may appear in .pc files. If the environment variable is not set, the default value '$(top_builddir)' will be used. This variable should refer to the top builddir of the Makefile where the compile/link flags reported by pkg-config will be used. This only matters when compiling/linking against a package that hasn't yet been installed. PKG_CONFIG_DISABLE_UNINSTALLED Normally if you request the package "foo" and the package "foo-uninstalled" exists, pkg-config will prefer the "-uninstalled" vari- ant. This allows compilation/linking against uninstalled packages. If this environment variable is set, it disables said behavior. PKG_CONFIG_ALLOW_SYSTEM_CFLAGS Don't strip -I/usr/include out of cflags. PKG_CONFIG_ALLOW_SYSTEM_LIBS Don't strip -L/usr/lib out of libs PKG_CONFIG_SYSROOT_DIR Modify -I and -L to use the directories located in target sysroot. this option is usefull when crosscompiling package that use pkg- config to determine CFLAGS anf LDFLAGS. -I and -L are modified to point to the new system root. this means that a -I/usr/include/libfoo will become -I/var/target/usr/include/libfoo with a PKG_CONFIG_SYSROOT_DIR equal to /var/target (same rule apply to -L) PKG_CONFIG_LIBDIR Replaces the default pkg-config search directory. WINDOWS SPECIALITIES
If a .pc file is found in a directory that matches the usual conventions (i.e., ends with libpkgconfig), the prefix for that package is assumed to be the grandparent of the directory where the file was found, and the prefix variable is overridden for that file accordingly. In addition to the PKG_CONFIG_PATH environment variable, the Registry keys HKEY_CURRENT_USERSoftwarepkgconfigPKG_CONFIG_PATH and HKEY_LOCAL_MACHINESoftwarepkgconfigPKG_CONFIG_PATH can be used to specify directories to search for .pc files. Each (string) value in these keys is treated as a directory where to look for .pc files. AUTOCONF MACROS
PKG_CHECK_MODULES(VARIABLE-PREFIX,MODULES[,ACTION-IF-FOUND,[ACTION-IF-NOT-FOUND]]) The macro PKG_CHECK_MODULES can be used in configure.ac to check whether modules exist. A typical usage would be: PKG_CHECK_MODULES([MYSTUFF], [gtk+-2.0 >= 1.3.5 libxml = 1.8.4]) This would result in MYSTUFF_LIBS and MYSTUFF_CFLAGS substitution variables, set to the libs and cflags for the given module list. If a module is missing or has the wrong version, by default configure will abort with a message. To replace the default action, specify an ACTION-IF-NOT-FOUND. PKG_CHECK_MODULES will not print any error messages if you specify your own ACTION-IF-NOT-FOUND. However, it will set the variable MYSTUFF_PKG_ERRORS, which you can use to display what went wrong. Note that if there is a possibility the first call to PKG_CHECK_MODULES might not happen, you should be sure to include an explicit call to PKG_PROG_PKG_CONFIG in your configure.ac PKG_PROG_PKG_CONFIG([MIN-VERSION]) Defines the PKG_CONFIG variable to the best pkg-config available, useful if you need pkg-config but don't want to use PKG_CHECK_MOD- ULES. PKG_CHECK_EXISTS(MODULES, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND]) Check to see whether a particular set of modules exists. Similar to PKG_CHECK_MODULES(), but does not set variables or print errors. Similar to PKG_CHECK_MODULES, make sure that the first instance of this or PKG_CHECK_MODULES is called, or make sure to call PKG_CHECK_EXISTS manually METADATA FILE SYNTAX
To add a library to the set of packages pkg-config knows about, simply install a .pc file. You should install this file to libdir/pkgcon- fig. Here is an example file: # This is a comment prefix=/home/hp/unst # this defines a variable exec_prefix=${prefix} # defining another variable in terms of the first libdir=${exec_prefix}/lib includedir=${prefix}/include Name: GObject # human-readable name Description: Object/type system for GLib # human-readable description Version: 1.3.1 URL: http://www.gtk.org Requires: glib-2.0 = 1.3.1 Conflicts: foobar <= 4.5 Libs: -L${libdir} -lgobject-1.3 Libs.private: -lm Cflags: -I${includedir}/glib-2.0 -I${libdir}/glib/include You would normally generate the file using configure, of course, so that the prefix, etc. are set to the proper values. Files have two kinds of line: keyword lines start with a keyword plus a colon, and variable definitions start with an alphanumeric string plus an equals sign. Keywords are defined in advance and have special meaning to pkg-config; variables do not, you can have any variables that you wish (however, users may expect to retrieve the usual directory name variables). Note that variable references are written "${foo}"; you can escape literal "${" as "$${". Name: This field should be a human-readable name for the package. Note that it is not the name passed as an argument to pkg-config. Description: This should be a brief description of the package URL: An URL where people can get more information about and download the package Version: This should be the most-specific-possible package version string. Requires: This is a comma-separated list of packages that are required by your package. Flags from dependent packages will be merged in to the flags reported for your package. Optionally, you can specify the version of the required package (using the operators =, <, >, >=, <=); specifying a version allows pkg-config to perform extra sanity checks. You may only mention the same package one time on the Requires: line. If the version of a package is unspecified, any version will be used with no checking. Conflicts: This optional line allows pkg-config to perform additional sanity checks, primarily to detect broken user installations. The syntax is the same as Requires: except that you can list the same package more than once here, for example "foobar = 1.2.3, foobar = 1.2.5, foobar >= 1.3", if you have reason to do so. If a version isn't specified, then your package conflicts with all versions of the men- tioned package. If a user tries to use your package and a conflicting package at the same time, then pkg-config will complain. Libs: This line should give the link flags specific to your package. Don't add any flags for required packages; pkg-config will add those automatically. Libs.private: This line should list any private libraries in use. Private libraries are libraries which are not exposed through your library, but are needed in the case of static linking. Cflags: This line should list the compile flags specific to your package. Don't add any flags for required packages; pkg-config will add those automatically. AUTHOR
pkg-config was written by James Henstridge, rewritten by Martijn van Beers, and rewritten again by Havoc Pennington. Tim Janik, Owen Tay- lor, and Raja Harinath submitted suggestions and some code. gnome-config was written by Miguel de Icaza, Raja Harinath and various hackers in the GNOME team. It was inspired by Owen Taylor's gtk-config program. BUGS
pkg-config does not handle mixing of parameters with and without = well. Stick with one. pkg-config(1)
All times are GMT -4. The time now is 08:08 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy