How to save and execute a C shell scrip?

Posted on 2011-10-27
Last Modified: 2012-06-27
I have a simple Cshell script as follows:

#! /bin/csh -f
set SourceDir = /home/milligram/mnt
set DestDir_IOS = Myvideos/IOS
chdir $SourceDir

foreach directory (`ls`)

test -d "$SourceDir/$directory" && echo "$SourceDir/$directory"


How do I save and execute the above script to a file in ubuntu and execute it via a terminal session?

where should I store the script?

Question by:wademi
    LVL 31

    Accepted Solution

    Open your favorite editor and paste the code into the file.

    For example use vi

    vi script.csh

    The press i to bring it to insert mode and paste the code

    then hit Esc to bring to command mode and do
    :x (enter)

    File is saved.
    Now issue command
    chmod +x script.csh

    And run it

    LVL 76

    Expert Comment

    To redirect the output to a file you would use
    ./script.csh > filename_where_results_will_be_stored

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    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 (…
    FreeBSD on EC2 FreeBSD ( is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

    729 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

    18 Experts available now in Live!

    Get 1:1 Help Now