How do I declare c shell variables with a list of directory paths and use them in foreach

Posted on 2011-10-29
Last Modified: 2012-05-12
How do I declare c shell variables with a list of directory paths ?

I tried the following but I dont think its correct.

set DestDir[1] = /home/milligram/MyVideos/In
set DestDir[2] = /home/milligram/MyVideos/Is
set DestDir[3] = /home/milligram/MyVideos/IT
set DestDir[4] = /home/milligram/MyVideos/Ho
set DestDir[5] = /home/milligram/MyVideos/FM)
#set DestDir = (/home/milligram/MyVideos/In /home/milligram/MyVideos/Is /home/milligram/MyVideos/Ho /home/milligram/MyVideos/FM /home/milligram/MyVideos/IT)

how do I execute foreach loops with the paths?

Is this corret?

foreach dest ($DestDir)

echo $dest

Question by:wademi
    LVL 31

    Accepted Solution

    Yes, it is correct.

    set DestDir = (/home/milligram/MyVideos/In /home/milligram/MyVideos/Is /home/milligram/MyVideos/Ho /home/milligram/MyVideos/FM /home/milligram/MyVideos/IT)

    foreach dest ($DestDir)

    echo $dest

    LVL 40

    Expert Comment

    if you are interested in creating / setting arrays then look at links below

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (…
    Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap ( Version 1.2 2.      Jpcap( Version 0.6 Prerequisite: 1.      GCC …
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now