Search code examples
scriptingcsh

how to make an if-else in csh script


I'm trying to make an if-else in csh script but it is not working:

do you know why this is not working?

if($2 == "rx" && $3 == "2") then
  setenv project_name       "mipi_2_rx_core_ns"
  setenv synth_logfile_name "mipi_2_rx_core_ns_syn"
  echo "RX 2 lanes"
  endif
  else if ($2 == "rx" && $3 == "4")
    setenv project_name       "mipi_4_tx_core_ns"
    setenv synth_logfile_name "mipi_4_tx_core_ns_syn"
    echo "RX 4 lanes"
endif
  else if ($2 == "plldig")
    setenv project_name       "dphyplldig"
    setenv synth_logfile_name "dphyplldig_syn"
  endif  
  else
    echo "No options specified"

endif

Solution

  • See the if else placement. You are missing then after ifs

    #!/bin/csh
    
    if ($2 == "rx" && $3 == "2") then
        setenv project_name       "mipi_2_rx_core_ns"
        setenv synth_logfile_name "mipi_2_rx_core_ns_syn"
        echo "RX 2 lanes"
    else if ($2 == "rx" && $3 == "4") then
        setenv project_name       "mipi_4_tx_core_ns"
        setenv synth_logfile_name "mipi_4_tx_core_ns_syn"
        echo "RX 4 lanes"
    else if ($2 == "plldig") then
        setenv project_name       "dphyplldig"
        setenv synth_logfile_name "dphyplldig_syn"
    else
        echo "No options specified"
    endif