Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8755715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:54:31+00:00 2026-06-13T13:54:31+00:00

I’m having trouble doing something basic with csh. I have a string: set newCmd

  • 0

I’m having trouble doing something basic with csh. I have a string:

set newCmd = "$expansionCmd –option1 –option2 …"

And I’m creating an array of these strings, which I later want to execute:

set expansionCmdList = ($expansionCmdList[*] "$newCmd")   
#I also tried without quotes, e.g. just $newCmd

Finally I try to iterate over and execute these commands:

foreach exCmd ($expansionCmdList) 
    `exCmd`    #execute it in the shell
end 

However the problem is that the array entries are not the full string, but every part of the string separated by whitespace, i.e. the first entry is just “$expansionCmd”, the next entry would be “—option1” etc.

Apologies in advance for using c shell, my company’s code base is stuck with it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:54:32+00:00Added an answer on June 13, 2026 at 1:54 pm

    Any time you are expanding an entire array and want to keep its individual elements’ identities intact, you need the :q (for “quoted”) modifier on the expansion. Otherwise, as soon as you do something like set expansionCmdList=($expansionCmdList[*] "$newCmd"), all previous commands in the list are split out into their component words, each of which is now its own array element. Simple demonstration:

    % set a = ( a "b c" d )
    % echo $a[2]
    b c
    % set a = ( $a[*] e )
    % echo $a[2]
    b
    

    Oops, you’ve messed up the array before you even get to your execution loop. Things go much better with :q:

    % set a = ( a "b c" d )
    % set a = ( $a:q e )
    % echo $a[2]
    b c
    

    You need to use the same modifier in the for loop:

    foreach exCmd ($expansionCmdList:q) 
    

    Finally, `exCmd` tries to run a command literally named “exCmd”, and then take its output and run that as a command. What you probably want to do is simply execute a command equal to the value of the variable. You will likely run into more whitespace woes here, and you can’t solve them by making each command an array since csh doesn’t support arrays of arrays. Fair warning. But if the commands don’t have any quotation needs, this will work:

      $exCmd
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having trouble doing something that is probably pretty simple! I have a
I'm having a lot of trouble doing something very simple. I have a viewController
I am having trouble doing a reverse URL lookup for Django-generated feeds. I have
I'm having some trouble doing a very simple task. I have a rich textbox
I'm just starting with jQuery, and having trouble doing something embarrassingly simple: using .load()
Sorry if this is a basic question: I am having trouble doing form validation
I am having trouble doing something simple like the following using (SPSite site =
I'm having trouble doing an aggregation query on a many-to-many related field. Here are
This is a seemingly simple problem but I am having trouble doing it in
Whilst doing exam revision I am having trouble answering the following question from the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.