How do I set a variable to a command's output in csh?

I have a number in a text file like :

int_width: 5230

I want to set this number (5230) to a variable in csh. What is the correct form? (grep is working before setting)

set WIDTH = "$(grep int_width *.txt | sed 's/[^0-9]*//g')"
1

1 Answer

  1. In order to set variable in csh you need to use set (more info)
  2. As mentioned by @muru comment - The original Bourne shell, csh or tcsh all do not support $() and require ` ` for command substitution.

Combine the above two and you'll get:

% set WIDTH=`grep int_width *.txt | sed "s,[^0-9]*,," `
% echo $WIDTH
5230

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like