3 Replies Latest reply on Feb 23, 2015 8:22 PM by Raja Mohan

    Extracting substrings with NSH

    Steve Cupp

      So. . I have a variable, $app_drive_value, that I define from a text file.


      Like so,

      app_drive_value=`head -n 1 /c/app_drive.txt`.


      I then want to check it's value like so,

      if [[ $app_drive_value = "C:" ]]





      Then check it again,

      if [[ $app_drive_value = "D:" ]]





      There is some invisible character at the end of the string that doesn't allow the if statements to work.

      So, all I really want are the first 2 characters of this string. .

      I found this syntax, ${string:position:length}, it looked really promising


      Used it like so,

      echo ${app_drive_value:0:2}


      Get this error:

      Error    02/22/2015 19:41:52    //@/C/Program Files/BMC Software/BladeLogic/NSH/tmp/job_deployment_2_NODCAPTBMC03/scripts/job__deb98870-8cd8-4300-8830-4225e59f7ae7/script_DBKey-SJobKeyImpl-45148-1__2444eea8-3fb4-4c57-9b74-426141a95bd2.138132.1_set_app_drive_property..nsh:40: unrecognized modifier `0'


      Can anyone help me get just the first 2 characters of this string?


      Thanks. . .