试图传递字符串值进行打印

时间:2014-07-23 19:17:33

标签: bash scripting

通过bash shell脚本,我正在尝试读取文件名。

    for File in `ls -1 ${OFSR_IN}/FACT_PEOPLE_*.txt`
     do
      File_name=`basename ${File}`
      EXT_YEARMTH=`basename ${File} .txt | cut -c13-`

      echo ${EXT_YEARMTH}
      echo  ${File_name}

      #OfsrHRSPeople05Loa
      echo "\$InputFile_People=\$PMRootDir\rlhrs\data\in\'${File_name}'" >>  ${OFSR_CFG}/pmserver_OfsrHRSPeople05Loa.prm
      echo "\$\$HR_YEARMONTH=${EXT_YEARMTH}" >> ${OFSR_CFG}/pmserver_OfsrHRSPeople05Loa.prm
    done


I am trying to print the value of File_name in output file config.prm







    echo "\$InputFile_People=\$PMRootDir\rlhrs\data\in\${File_name}" >> ${OFSR_CFG}/config.prm
echo "\$\$HR_YEARMONTH=${EXT_YEARMTH}" >> ${OFSR_CFG}/pmserver_OfsrHRSPeople05Loa.prm

我无法打印正确的文件名,例如filename_201401.txt

我出去了

 $InputFile_People=$PMRootDir\rlhrs\data\in\'FACT_PEOPLE_201306.txt'
$$HR_YEARMONTH=201401

我希望我的输出在文件名中没有引号

    $InputFile_People=$PMRootDir\rlhrs\data\in\FACT_PEOPLE_201306.txt
$$HR_YEARMONTH=201401

2 个答案:

答案 0 :(得分:0)

请试试这个:

  1. 使用" ls -1"而不只是你的for循环中的ls。
  2. 转义echo语句中的反斜杠

    echo" $ {InputFile_People} = $ {PMRootDir} \ rlhrs \ data \ in \ $ {File_name}" >> $ {OFSR_CFG} /config.prm

  3. 另外请分享一些您期望从echo语句中获得的示例输出。它有助于更​​好地理解问题。

答案 1 :(得分:0)

Change  echo "\$InputFile_People=\$PMRootDir\rlhrs\data\in\'${File_name}'" >>  ${OFSR_CFG}/pmserver_OfsrHRSPeople05Loa.prm to  echo "\$InputFile_People=\$PMRootDir\rlhrs\data\in\\${File_name}" >> "${OFSR_CFG}/pmserver_OfsrHRSPeople05Loa.prm" as given by Konsolexbox