bash脚本中的变量未按预期工作

时间:2015-05-08 16:24:15

标签: linux bash

我有这个脚本:

<video id="vd_file" runat="server" controls="controls" 
       width="400px" height="300px" src="" />

string ss =ec.Getds("select product_other4 from products where Product_Id='6' " );

vd_file.InnerHtml = "<video src=\"" + ss + " \"   id=\"vd_file\"   runat=\"server\"   controls=\"controls\"   width=\"400px\"   height=\"300px\"    /> " ;

但如果我运行此脚本,我会收到此错误:

#!/bin/bash
VAR="eric.sql"
sudo mysqldump -c -u username -p1234 dbname > $VAR

但如果我不使用变量,只需这样:

: Protocol error 3: mysql-export.sh: cannot create eric.sql

......它运作良好。我错了什么?

2 个答案:

答案 0 :(得分:1)

问题是该脚本有Windows样式换行符(我用过记事本)。在我使用Nano后,编写脚本就解决了。

感谢您的回答!

答案 1 :(得分:-2)

sudo可以更改$ PATH变量,具体取决于您的安全策略。

   -E  The -E (preserve environment) option will override the env_reset
       option in sudoers(5)).  It is only available when either the match-
       ing command has the SETENV tag or the setenv option is set in sudo-
       ers(5).

您可以添加文件的完整路径,也可以删除该脚本中的sudo。 这也应该有效:

 sudo PATH="$PATH" mysqldump -c -u username -p1234 dbname > $VAR
相关问题