Visit Our UNIX and Linux User Community

Bash: Help with output from a for loop

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash: Help with output from a for loop
# 1  
Old 09-25-2009
Bash: Help with output from a for loop


Sorry I'm new to shell scripting..

my loop is as follows:

let i=0
for item in ${APPSARRAY[@]}
          #..some code to get a unique value called $result
          let i=i+1

What I want to do is within the for loop, create a comma seperated list:

which I can then use outside of the loop...Can anyone help me?

Much appreciated!!!


Last edited by zaxxon; 09-25-2009 at 07:12 AM.. Reason: code tags and formatting
# 2  
Old 09-25-2009
where do you get $result from ?

let i=0
for item in ${APPSARRAY[@]}
          #..some code to get a unique value called $result
         let i=i+1
echo $output # should have whatever you want

Can you expand on what is required ?
# 3  
Old 09-25-2009

i think it should be:

# 4  
Old 09-25-2009
printf -v output "%s," "${APPSARRAY[@]}"

Previous Thread | Next Thread
Test Your Knowledge in Computers #239
Difficulty: Easy
In March 1970, the ARPANET reached the East Coast of the United States, when an IMP at the Department of Energy in Washington, DC was connected to the network.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How do I assign the output of a command to a variable within a loop in bash?

In the else of the main if condition . else set lnk = $(readlink -f <path> | cut -d '/' -f7) echo "$lnk" if ] When I run the above on command line , the execution seems to be fine and I get the desired output. But when I try to assign it to a variable within a loop... (12 Replies)
Discussion started by: sankasu
12 Replies

2. Shell Programming and Scripting

For loop in bash - Direct output to two files

Hello all, i have a code in which when doing a for loop, i need to direct the output to two files, one just a single output, the other to always append (historical reasons). So far i managed to do the following, which is working, but am still considering it as "dirty". ... (4 Replies)
Discussion started by: nms
4 Replies

3. Shell Programming and Scripting

Help on for loop in bash

Hi, In the code "for loop" has been used to search for files (command line arguments) in directories and then produce the result to the standard output. However, I want when no files are named on the command line, it should read a list of files from standard input and it should use the command... (7 Replies)
Discussion started by: Ra26k
7 Replies

4. Shell Programming and Scripting

BASH - Need to echo for loop output to one line

I'm trying to echo the release version of some of our Linux servers. Typically I do these types of things by "catting" a text file with the host names, "ssh-ing" to the host and running my string. This is what I've written for i in `cat versions.txt` ; do echo $i ; ssh $i cat /etc/issue |... (5 Replies)
Discussion started by: lombardi4851
5 Replies

5. Shell Programming and Scripting

Bash For Loop Help

This is a short program I wrote to search through a directory and move files containing the keyword to a folder. #!/bin/bash echo 'What is the directory?' read DIR echo -e '\n' echo 'What is the keyword?' read KEY echo -e '\n' cd $DIR rmdir 'relevant_files' mkdir 'relevant_files'... (5 Replies)
Discussion started by: zenyoul
5 Replies

6. Shell Programming and Scripting

If loop in bash

Hello, I have a script that runs a series of commands. Halfway through the script, I want it to check whether everything is going alright: if it is, to proceed with the script, if it isn't to repeat the last step until it gets it right. My code so far looks like this, simplified a bit: ... (3 Replies)
Discussion started by: Leo_Boon
3 Replies

7. Shell Programming and Scripting

BASH loop inside a loop question

Hi all Sorry for the basic question, but i am writing a shell script to get around a slightly flaky binary that ships with one of our servers. This particular utility randomly generates the correct information and could work first time or may work on the 12th or 100th attempt etc !.... (4 Replies)
Discussion started by: rethink
4 Replies

8. Shell Programming and Scripting

Using variables created sequentially in a loop while still inside of the loop [bash]

I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends. As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies

9. Shell Programming and Scripting

bash and ksh: variable lost in loop in bash?

Hi, I use AIX (ksh) and Linux (bash) servers. I'm trying to do scripts to will run in both ksh and bash, and most of the time it works. But this time I don't get it in bash (I'm more familar in ksh). The goal of my script if to read a "config file" (like "ini" file), and make various report.... (2 Replies)
Discussion started by: estienne
2 Replies

10. Shell Programming and Scripting

Why generate "ash and bash" different output for same bash script?

Hi, For my bash script, terminal with bash is generate an OK output and program works right. already, terminal with ash have "line 48: syntax error: Bad substitution" output and program don't work. :confused: (0 Replies)
Discussion started by: s. murat
0 Replies

Featured Tech Videos