Using \n in csh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using \n in csh
# 1  
Old 11-16-2010
Using \n in csh

I am trying to use \n for a new line in csh like this

Code:
echo "some text\n"
echo "some more text\n"

but am getting

Code:
some text\n
some more text\n

# 2  
Old 11-16-2010
I see following:
Code:
 
%echo "abc\n"
abc
 
%

# 3  
Old 11-16-2010
This did not work.

Code:
if ($opt_npop == 1) echo " -npop = $npop\n"

# 4  
Old 11-16-2010
Working for me:
Code:
 
#!/usr/bin/csh
echo "Hi\n";
set opt=1;
set op1="abcdef";
echo $opt
if($opt == 1) echo "-nopt=$opt\n";

Result:
Code:
Hi
 
1
-nopt=abcdef
 
%

Show more code please..
# 5  
Old 11-16-2010
Quote:
Originally Posted by kristinu
This did not work.

Code:
if ($opt_npop == 1) echo " -npop = $npop\n"

What it is not work?
There is not seem any error
# 6  
Old 11-16-2010
Code:
  set ierr = 0
  set iarg = 0
  set opt_tpath = 0
  set opt_fbase = 0
  set opt_fdata = 0
  set opt_fstmod = 0
  set opt_frestore = 0
  set opt_ftag = 0
  set opt_tee = 0
  set opt_nxz = 0
  set opt_npop = 0
  set opt_varp = 0
  set opt_sigma = 0
  set opt_maxiter = 0
  set opt_dtau = 0
  set opt_mdacc = 0
  set opt_mindist = 0
  set opt_maxitertp = 0
  set opt_vrb = 0
  set opt_usage = 0
  set opt_example = 0
  set opt_help = 0
  set opt_redirect = 0

  set nlay = 1
  set param = "P"
  set intp = "LIN"
  set std = "on"
  set frestore = ""
  set ftag = ""
  set Avrb = ""
  set tol = 0.0

  set Version = "V03"
  alias MATH 'set \!:1 = `echo "\!:3-$" | bc -l`'
  set narg = $#argv
  while ($iarg < $narg)

    MATH iarg = $iarg + 1
    set arg = $argv[$iarg]
    set opt = `echo $arg | awk 'BEGIN {FS="="} {print $1}'`
    set par = `echo $arg | awk 'BEGIN {FS="="} {print $2}'`

    switch ($opt)
    case "-tpath":
        set Atpath = $par
        set tpath = $Atpath
        set opt_tpath = 1
        breaksw
    case "-fbase":
        set Afbase = $par
        set fbase = `echo $Afbase | awk 'BEGIN {FS=".base"} {print $1}'`
        set opt_fbase = 1
        breaksw
    case "-fdata":
        set Adata = $par
        set fdata = `echo $Afdata | awk 'BEGIN {FS=".dat"} {print $1}'`
        set opt_fdata = 1
        breaksw
    case "-fstmod":
        set Afstmod = $par
        set fstmod = `echo $Afstmod | awk 'BEGIN {FS=".cmod"} {print $1}'`
        set opt_fstmod = 1
        breaksw
    case "-frestore":
        set Afrestore = $par
        set frestore = $Afrestore
        set opt_frestore = 1
        breaksw
    case "-ftag":
        set Aftag = $par
        set ftag = $Aftag
        set opt_ftag = 1
        breaksw
    case "-nxz":
        set Anxz = $par
        set nxz = $Anxz
        set nxp = `echo $Anxz | awk 'BEGIN {FS="x"} {print $1}'`
        set nzp = `echo $Anxz | awk 'BEGIN {FS="x"} {print $2}'`
        set opt_nxz = 1
        breaksw
    case "-npop":
        set Anpop = $par
        set npop = $Anpop
        set opt_npop = 1
        breaksw
    case "-varp":
        set Avarp = $par
        set varp = $Avarp
        set varpint = `echo $Avarp | awk 'BEGIN {FS="."} {print $1}'`
        set varpfrc = `echo $Avarp | awk 'BEGIN {FS="."} {print $2}'`
        set opt_varp = 1
        breaksw
    case "-sigma":
        set Asigma = $par
        set sigma0 = $Asigma
        set opt_sigma = 1
        breaksw
    case "-maxiter":
        set Amaxiter = $par
        set maxiter = $Amaxiter
        set opt_maxiter = 1
        breaksw
    case "-dtau":
        set Adtau = $par
        set dtau = $Adtau
        set opt_dtau = 1
        breaksw
    case "-mdacc":
        set Amdacc = $par
        set mdacc = $Amdacc
        set opt_mdacc = 1
        breaksw
    case "-mindist":
        set Amindist = $par
        set mindist = $Amindist
        set opt_mindist = 1
        breaksw
    case "-maxitertp":
        set Amaxitertp = $par
        set maxitertp = $Amaxitertp
        set opt_maxitertp = 1
        breaksw
    case "-vrb":
        set Avrb = $par
        set vrb = $Avrb
        set opt_vrb = 1
        breaksw
    case "-redirect":
        set Aredirect = $par
        set opt_redirect = 1
        breaksw
    default:
        set Aerr = $arg
        set ierr = 1
        breaksw
    endsw

  end   # while

  set arg1 = "../Scripts/tdarwin.csh"
  set arg2 = "[-tpath=] [-fbase=fbase.base] [-fdata=fdata.dat]"
  set arg3 = "[-fstmod=fstmod.cmod] [-frestore=restore.back] [-ftag=]"
  set arg4 = "-nxz= -npop= -varp= [-sigma=] [-maxiter=]"
  set arg5 = "[-dtau=] [-mdacc=] [-mindist=] [-maxitertp=]"
  set usage1 = "$arg1 $arg2 $arg3 $arg4 $arg5"
  set eg1 = "-fdata=npt06-z30-sr65.dat -fstmod=npt06-z30-sr65-4x3smp.cmod"
  set eg2 = "-nxz=8x6 -npop=480 -varp=0.25"
  set eg1 = "$arg1 $eg1 $eg2"

  if ($opt_tpath == 0) then
    set tpath = "/nethome/chrisd/GStat/Trunk/TommyCD/bin"
  endif

  if ($opt_fbase == 0) then

      set NF = `ls -lrt *.base  \
                | awk ' BEGIN{ORS=" "}; {print $NF} '  \
                | awk '{print NF}'`

      if ($NF > 1) then
        set msg = "ABORT: Multiple base files exist in directory"
        echo ""
        echo "ERROR: "$NF" base files exist"
        echo "       "$msg
        echo ""
        echo "        Set the base file using the -Base option"
        echo ""
        echo "End"
        echo ""
        exit 1
      endif

      set fbase = `ls -lrt *.base  \
                   | awk ' BEGIN{ORS=" "}; {print $NF} '  \
                   | awk '{print $1}'`

      set fbase = `echo $fbase | awk 'BEGIN { FS=".base" } { print $1 }'`

  endif

  if ($opt_fdata == 0) then

      set NF = `ls -lrt *.dat  \
                | awk ' BEGIN{ORS=" "}; {print $NF} '  \
                | awk '{print NF}'`

      if ($NF > 1) then
        set msg = "ABORT: Multiple data files exist in directory"
        echo ""
        echo "ERROR: "$NF" data files exist"
        echo "       "$msg
        echo ""
        echo "        Set the data file using the -Data option"
        echo ""
        exit 1
      endif

      set fdata = `ls -lrt *.dat  \
                   | awk ' BEGIN{ORS=" "}; {print $NF} '  \
                   | awk '{print $1}'`

      set fdata = `echo $fdata | awk 'BEGIN { FS=".dat" } { print $1 }'`

  endif

  if ($opt_tpath == 1) echo " -tpath = $tpath\n"

  if ($opt_fbase == 1) echo " -fbase = fbase.base = $fbase\n"

  if ($opt_fdata == 1) echo " -fdata = fdata.dat = $fdata\n"

  if ($opt_fstmod == 1) echo " -fstmod = fstmod.cmod = $fstmod\n"

  if ($opt_frestore == 1) echo " -frestore = frestore.back = $frestore\n"

  if ($opt_ftag == 1) echo " -ftag = $ftag\n"

  if ($opt_nxz == 1) echo " -nxz = $Anxz\n"

  if ($opt_npop == 1) echo " -npop = $npop\n"

  if ($opt_varp == 1) echo " -varp = $varp\n"

  if ($opt_sigma == 1) echo " -sigma = $sigma\n"

  if ($opt_maxiter == 1) echo " -maxiter = $maxiter\n"

  if ($opt_dtau == 1) echo " -dtau = $dtau\n"

  if ($opt_mdacc == 1) echo " -mdacc = $mdacc\n"

  if ($opt_mindist == 1) echo " -mindist = $mindist\n"

  if ($opt_maxitertp == 1) echo " -maxitertp = $maxitertp\n"

  if ($opt_vrb == 1) echo " -vrb = $vrb\n"

  if ($opt_redirect == 1) echo " -redirect\n"

---------- Post updated at 02:13 PM ---------- Previous update was at 02:11 PM ----------

Am getting like this

Code:
 -fstmod = fstmod.cmod = npt10-z30-sr65-rgdt0p25-dc0p25-4x3smp\n
 -nxz = 8x6\n
 -npop = 480\n
 -varp = 0.20\n

I know it's strange. Got no clue what's happening. Smilie

Last edited by kristinu; 11-16-2010 at 03:35 PM..
# 7  
Old 11-16-2010
is that full code or portion of your script?
and which command you use so what is your full command with positional parameters ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

What does this do in CSH?

CSH experts What does the following do in CSH? :(){:|:&};: I was asked the question, but I don't know. I'm not aware of the context. Any ideas? Thanks! (1 Reply)
Discussion started by: wallg
1 Replies

2. Shell Programming and Scripting

.sh to .csh

Hi All, Could any one of you give me a hand to convert the following line of codes from .sh to .csh please ? proc_id=`fuser /tmp/test` if then echo "File is not being used by any thing" fi if then echo "File is being used... please wait" sleep 1 fi Regards. (1 Reply)
Discussion started by: sraj142
1 Replies

3. Shell Programming and Scripting

if in csh

I am using this code echo "opt_tpath = $opt_tpath" if ($opt_tpath == 1) echo " -tpath = $Atpath\n" and is giving opt_tpath = 0 Atpath: Undefined variable. Atpath should only be printed in opt_tpath == 1 but it still tries to print. ---------- Post updated at 10:05 AM ----------... (1 Reply)
Discussion started by: kristinu
1 Replies

4. Shell Programming and Scripting

#!/bin/csh -f :: What does it mean

Hi, I have a script which I need to modify. It contains the following statement at the beginning - 1. What does this mean ? #!/bin/csh -f 2. If I run the following code in a script on C SHELL it runs normally. host=0 if ; then host="<<something>>" fi But, in the script... (7 Replies)
Discussion started by: angshuman_ag
7 Replies

5. UNIX for Dummies Questions & Answers

csh

what is a .csh extension? there is a command line: mkaphed_ctio.csh Does anyone know what this is? :confused::confused::confused: (1 Reply)
Discussion started by: cosmologist
1 Replies

6. Shell Programming and Scripting

csh failing to call an 2 embedded csh script

I have an extraordinary problem with a csh script.....(feel free to berate the use of this but I'm modifying an existing bunch of them) Anyway, I have a master csh script which in turn calls a second csh script. This second csh script is below. Within this second script are two compiled C++... (1 Reply)
Discussion started by: pollsizer
1 Replies

7. Shell Programming and Scripting

sh and csh issue

Hi I like to assign a command string to a variable to execute. In this case, set sshexec_parent_pid="ps -ef | grep $$ | awk '/bash -c/ {print $3}' | sort | head -1;`" echo $sshexec_parent_pid ; But I can't seem to get it to work. It gives me sshexec_parent_pid: Undefined variable. ... (2 Replies)
Discussion started by: mpc8250
2 Replies

8. UNIX for Dummies Questions & Answers

csh History

Hello everybody, Im being unsuccessful to enable command history logging in csh shells on a Sun machine running Solaris 9, I know csh doesnt log commands history by itself, here under is my /.cshrc file: # @(#)cshrc.standard 1.1 Copyright 1994, Motorola Inc. if ( -e /.datagen_system )... (8 Replies)
Discussion started by: aladdin
8 Replies

9. Shell Programming and Scripting

csh problem with while

Hello this my first post, so i hope you help me echo -n "Choose which square you want to hit of PL2 grid " set pl2_square = $< set i = 1 while ($i <= 6) if ($pl2_square == $pl2_ships) then $pl2_ships = x echo "" echo "" echo "PL1 has hitted a square of PL2" echo... (5 Replies)
Discussion started by: amaj1407
5 Replies

10. Shell Programming and Scripting

Need a better find for csh

At /home/me/bin I've got a script called fg. The meat of it is: find . -name "$1" | xargs grep $2 The intent is to call it as "fg file_pattern search_pattern" and search all matching files. I've added the directory to my path and made the file executable, but when I try to use it I get ... (3 Replies)
Discussion started by: James McMurray
3 Replies
Login or Register to Ask a Question