Ubuntu Shell Scripting Coding issues

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.