Making array of string with bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Making array of string with bash
# 1  
Old 09-11-2010
Making array of string with bash

in.txt
Code:
libgstreamer
gstreamer-0_10
gstreamer-0_10-plugins-good
gstreamer-0_10-plugins-base

Output should be:
Code:
libgstreamer gstreamer-0_10 gstreamer-0_10-plugins-good gstreamer0_10-plugins-base

Then:
Code:
#!/bin/sh
v=(libgstreamer gstreamer-0_10 gstreamer-0_10-plugins-good gstreamer0_10-plugins-base)
<package-management-tool> install ${v}

<package-management-tool> may be yum/apt-get etc.
# 2  
Old 09-11-2010
Do you need that "v" array for anything else? Cause it can be safely ommited:
Code:
<package-management-tool> install $(awk -vORS=" " '1' in.txt)

# 3  
Old 09-11-2010
Quote:
Originally Posted by bartus11
Do you need that "v" array for anything else? Cause it can be safely ommited:
Code:
<package-management-tool> install $(awk -vORS=" " '1' in.txt)

I want to do this with bash script.
# 4  
Old 09-11-2010
Quote:
Originally Posted by cola
I want to do this with bash script.
This command can be executed in bash script...
Code:
#!/bin/bash
<package-management-tool> install $(awk -vORS=" " '1' in.txt)

Will work.
# 5  
Old 09-11-2010
Posix:
Code:
<package-management-tool> install $(cat in.txt)

bash/ksh93
Code:
<package-management-tool> install $(<in.txt)

# 6  
Old 09-11-2010
Code:
#!/bin/sh
v=$( tr "\n" " " < in.txt)
<package-management-tool> install ${v}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Making an array of 2D arrays in C

I hate I'm asking for help again. Unfortunately it seems there just aren't any links I can find on making an array that holds a bunch of two dimensional arrays. Maybe my google-fu is lacking. Basically I have a header file like this: #define MATRIX 10 int white_l1; int white_l2; int... (2 Replies)
Discussion started by: Azrael
2 Replies

2. Shell Programming and Scripting

Bash arrays: rebin/interpolate smaller array to large array

hello, i need a bit of help on how to do this effectively in bash without a lot of extra looping or massive switch/case i have a long array of M elements and a short array of N elements, so M > N always. M is not a multiple of N. for case 1, I want to stretch N to fit M arrayHuge H = (... (2 Replies)
Discussion started by: f77hack
2 Replies

3. Shell Programming and Scripting

Bash 3.2 - Array / Regex - IF 3rd member in array ends in 5 digits then do somthing...

Trying to do some control flow parsing based on the index postion of an array member. Here is the pseudo code I am trying to write in (preferably in pure bash) where possible. I am thinking regex with do the trick, but need a little help. pesudo code if == ENDSINFIVEINTS ]]; then do... (4 Replies)
Discussion started by: briandanielz
4 Replies

4. Shell Programming and Scripting

Help in making a basic bash script

Hi All, I am trying to monitor CPU load of few processes, with the same name. The output that I get from top is the following 28171 root 20 0 1089m 21m 3608 S 103 0.3 15:16.89 /opt/ppp//h264rtptranscoder.bin --videoPort=14504 --audioPort=14505 27589 root 20 0 1060m 23m... (3 Replies)
Discussion started by: liviusbr
3 Replies

5. Shell Programming and Scripting

Use double quotes as part of the string in a Bash array

So I need to create an array that has " in the string of the text: string = ( "value 1" "value2" where the actual string is "value1" with the quotations included would this work? string = ( \"value1\" \"value\") and if the strings contain spaces as well: string = ("\"this... (4 Replies)
Discussion started by: os2mac
4 Replies

6. Shell Programming and Scripting

perl script :making array

Hi , i have a perl script which takes 'csv; file as input parameter and performs some tasks. CSV file format : MAGENTF,AGENTF8,mahfr001,tksfr01,. ./.profile 1>/dev/null 2>&1;ps -fe|grep 'gn1avm_agent -n AGENTF8'|grep gn1avm_agent|tr -s '' ''|cut -d ' ' -f 3|xargs kill -9,,. ./.profile... (3 Replies)
Discussion started by: deepakiniimt
3 Replies

7. Shell Programming and Scripting

PERL : Read an array and write to another array with intial string pattern checks

I have an array and two variables as below, I need to check if $datevar is present in $filename. If so, i need to replace $filename with the values in the array. I need the output inside an ARRAY How can this be done. Any help will be appreciated. Thanks in advance. (2 Replies)
Discussion started by: irudayaraj
2 Replies

8. Shell Programming and Scripting

bash: making a count

ok basically im trying to count how many people fail a class by comparing there grade by -gt 49 i tried putting a count inside the while loop but i know you cant access a count outside a subshell. is there an easy way to count the number of failures? declare -i failcount=0 awk... (2 Replies)
Discussion started by: nilekyle
2 Replies

9. Shell Programming and Scripting

split and making an array inside another array

I want to run an awk split on a value that has been pushed through an array and I was wondering what the syntax should be?? e.g. running time strings through an array and trying to examine just minutes: 12:25:30 10:15:13 08:55:23 awk ' NR==FNR{ ... (2 Replies)
Discussion started by: dcfargo
2 Replies

10. UNIX for Dummies Questions & Answers

Making Application by bash

I'm using Mac OSX. And i want to make an visual application based on bash command. But, apple script doesn't support Terminal command. So please tell me how to turn my dream into a reality. :o I mean purely by bash! (0 Replies)
Discussion started by: Euler04
0 Replies
Login or Register to Ask a Question