Today, a colleague is writing a database backup shell script, in the case of several times to determine the script code is correct, found that the results of the script output is not normal.
/* * * @author Jenkihuang * @email [email protected] * @version 20150407 */#!/bin/bashdata_dir= "/home/oracle/bakup/data" Logs_dir= "/home/oracle/bakup/logs" Deltime= ' date-d "7 days Ago" +%y%m%d ' btm= ' Date "+%y%m%d%h%m%s" ' Filename= "$DATA _ Dir$btm.dmp "echo" Starting bakup ... "Echo $FILENAME
After the executable permission is set on the file, the output is executed when the script executes
sudo ./oracleautobk. SH starting Bakup....dmp0407165921akup/data
Above the second ECHO statement is obviously wrong, helpless in the Internet to find information, and finally in Bing (seldom use degree Niang search, Google search everyone understand) found in the shell script coding problems. It turns out that the colleague is not writing the VI editor directly when writing the script. Instead, it was written with UE on Windows and uploaded to the Linux system using FTP tools. So now the problem is that the default format for shell scripts written in Windows systems is DOS instead of UNIX, resulting in incorrect output results.
Look at the format of the shell script and edit the shell script with VI. Then enter ": Set FF?" If the output end is "Fileformat=dos", you need to modify the format of the file
// modify file format, open shell script with VI input : set ff=UNIX// then save exit
Execute the script file again, the file name of date format can be output correctly
sudo ./oracleautobk. SH starting Bakup ... /home/oracle/bakup/data20150407171543.dmp
So in this view, later scripting or directly in the Linux system using VI writing more real. A skilled vi editor, and secondly can also avoid unnecessary trouble.
Reprint: http://www.jenkihuang.com/experience/2015/04/ubuntu-shell-charset.html
Ubuntu Shell Scripting Coding issues