我有一个shell脚本,该脚本从文件中插入行,然后通过mysql将它们发送到数据库。但是,它正在读取的某些行包含双引号。
示例-This is a "line from a file" with words
此行结束时将其放入变量中,以馈送到mysql命令中以将其发送到数据库。这就是问题所在。变量中的引号引起mysql命令错误。
示例:
MySQLString='INSERT INTO MyTable (`id`, `line`,) VALUES (NULL, "'"$LifeFromFile"'")'
mysql -uName -pPass --execute "$MySQLString"
答案 0 :(得分:2)
您可能要在这里使用body {
background-color: #fff;
margin: 0 auto;
}
.section1 {
position: relative;
background-color: #3d3d3d;
width: 100%;
height: 400px;
}
.search_bar_container {
position: absolute;
width: calc(100% - 40px);
height: 50px;
margin: 0 auto;
background-color: white;
bottom: 50px;
left: 50%;
transform: translate(-50%);
-webkit-transform: translate(-50%);
-moz-transform: translate(-50%);
border-radius: 25px;
overflow: hidden;
box-shadow: 0px 0px 13px rgba(0, 0, 0, 0.50);
-webkit-box-shadow: 0px 0px 13px rgba(0, 0, 0, 0.50);
-moz-box-shadow: 0px 0px 13px rgba(0, 0, 0, 0.50);
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
.right_arrow_icon_container {
position: absolute;
right: 10px;
width: 30px;
height: 30px;
background-color: #13c8b0;
border-radius: 15px;
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
z-index: 15;
cursor: pointer;
display: none;
}
.right_arrow_icon_container:hover {
background-color: #0fac90;
transition: all 0.2s ease;
}
.left_arrow_icon_container {
position: absolute;
left: 10px;
width: 30px;
height: 30px;
background-color: #13c8b0;
border-radius: 15px;
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
z-index: 15;
cursor: pointer;
display: none;
}
.left_arrow_icon_container:hover {
background-color: #0fac90;
transition: all 0.2s ease;
}
.search_bar_button1 {
width: 100%;
height: 100%;
border: none;
outline:none !important;
display: none;
position: absolute;
padding: auto;
background-color: #13c8b0;
z-index: 20;
font-family: 'Lato', sans-serif;
font-size: 20px;
font-weight: 100;
color: #fff;
text-decoration: none;
cursor: pointer;
transition: all 0.2s ease;
}
.search_bar_button1:hover {
background-color: #0fac90;
transition: all 0.2s ease;
}
.search_bar_input {
height: 40px;
position: relative;
display: flex;
flex-direction: row;
justify-content: space-around;
align-items: center;
background-color: ;
transition: all 0.2s ease;
}
.input_location {
width: calc(33% - 50px);
}
.input_dates {
width: calc(33% - 50px);
}
.input_guests {
width: calc(33% - 50px);
}
.search_bar_button2 {
width: 150px;
height: 100%;
border: none;
border-radius: 25px;
-webkit-border-radius: 25px;
-moz-border-radius: 25px;
outline:none !important;
display: block;
padding: auto;
background-color: #13c8b0;
z-index: 18;
font-family: 'Lato', sans-serif;
font-size: 20px;
font-weight: 100;
color: #fff;
text-decoration: none;
cursor: pointer;
transition: all 0.2s ease;
}
.search_bar_button2:hover {
background-color: #0fac90;
transition: all 0.2s ease;
}
input[type="text"] {
transition: all 0.3s ease;
-ms-box-sizing:content-box;
-moz-box-sizing:content-box;
-webkit-box-sizing:content-box;
color: #4d4d4d;
outline: none;
border: 0;
outline: 0;
border: none;
background-color: ;
padding:5px 5px 5px 46px;
font-size:20px;
width: calc(100% - 51px);
height: 30px;
font-family: 'Lato', sans-serif;
}
.search_bar_input_icon {
position: absolute;
left: 20px;
background-color: purple;
}
.vl {
border-left: 1px solid #808080;
height: 35px;
}
@media all and (min-width: 1200px) {
.search_bar_container {
width: 1200px;
}
}
@media all and (max-width: 960px) {
.input_location {
width: calc(39% - 50px);
}
.input_dates {
width: calc(30% - 50px);
}
.input_guests {
width: calc(30% - 50px);
}
.search_bar_button2 {
width: 120px;
}
input[type="text"] {
padding:5px 5px 5px 36px;
width: calc(100% - 41px);
}
.search_bar_input_icon {
left: 10px;
}
}
@media all and (max-width: 768px) {
.input_location {
width: calc(38% - 50px);
}
.input_dates {
width: calc(35% - 50px);
}
.input_guests {
width: calc(26% - 50px);
}
}
@media all and (max-width: 680px) {
.left_arrow_icon_container {
display: block;
}
.right_arrow_icon_container {
display: block;
}
.search_bar_button1 {
display: block;
transition: all 0.2s ease;
}
#button1 {
left: 0;
transition: all 0.2s ease;
}
.input_location {
width: 100%;
position: absolute;
transition: all 0.2s ease;
left: 100%;
}
.input_dates {
width: 100%;
position: absolute;
transition: all 0.2s ease;
left: 200%;
}
.input_guests {
width: 100%;
position: absolute;
transition: all 0.2s ease;
left: 300%;
}
.search_bar_button2 {
width: 100%;
position: absolute;
transition: all 0.2s ease;
left: 400%;
}
input[type="text"] {
padding:5px 5px 5px 86px;
}
.search_bar_input_icon {
left: 60px;
}
}
:
printf
line='This is a "line from a file" with words'
printf -v sqlStr "INSERT INTO MyTable (id, line) VALUES (NULL, '%s')" "$line"
echo "$sqlStr"