我有一个程序,它接受单个规则文件形式的一组规则。
当我的程序认为满足其中一个条件时,我会将与该条件相关联的命令块视为需要执行的独立bash脚本。我不想将这些命令存储在文件中,因为这会留下一个不受欢迎的攻击向量。是否有一种方法可以将bash命令作为一个单独的组提供给以行分隔的bash命令列表?我希望if条件和bash脚本中的其他内容能够正确运行,而不仅仅是单独执行每一行。
规则文件示例:
if CONDITION
some nice
bash commands
pkill some process
./launching something!
endif
当条件为真时,我希望能够将这四行bash
为什么这个命令行工作:
$ output='Irrelevant'; if [[ $output =~ Something ]]; then echo "I found something in the output." ; fi
这个给了我一个奇怪的解析错误?
$ output='Irrelevant'; if [[ $output =~ Something ]]; then echo "I found something in the output!" ; fi
-bash: !": event not found
与
我正在尝试将数据导入postgres。数据字段是逗号分隔的,字符串可能包含逗号,在这种情况下,这些逗号是转义的:
数据结构:
create table v (a varchar);
数据文件:
bus
'Gat\,\\e\'way_MQB'
导入命令(在Linux下从bash运行)
cat data.csv | psql -d database -c "copy v (a) from stdin with delimiter ',' escape '\\' CSV header"
错误:
ERROR: extra dat
我是个新手。我想调用位于远程linux机器上的脚本,传递一些普通参数和一个数组。数组包含可能有空格的字符串元素。
我写了一个最小的例子:
服务器端: copyFiles.sh
#!/bin/bash
msg=$1
msg2=$2
shift
shift
arr=("$@") # Rebuild the array with rest of arguments
for ((i = 0; i < ${#arr[@]}; i++))
do
echo $msg $msg2 "${arr[$i]}"
done
在东道方面:
fir
我在linux上查询mysql有问题,我的查询有2色"-“:
mysql -u root -pPass mydb -e "select `work-time` from work where `work-time`> '2013-0-3-07 00:00:00'";
但结果是:
bash: work-time: command not found
我知道这句"`“的问题,但如何解决这个问题呢?
I更新我的查询
在线解决查询:
mysql -u root -pPass mydb -e "select \`work-time\` fro
我正在尝试运行一些bash脚本,这些脚本是我们在上在Linux上编写的。脚本执行一个
#!/bin/bash
sudo su -l <username> << EOF
echo $HOME
#execute command that is only on the path of <username>
EOF
不,我以user1的身份运行脚本,在脚本中我试图切换到user2。实际上,我需要它像这样运行,因为还有其他部分需要以user1的形式运行。
在linux上我得到
/home/user2
在上我得到
/Users/user1
因此,它实际上并不执行登录,
当我使用bash时,cd命令不起作用,并显示他们没有这样的文件或目录,即使它存在。
hudson@DESKTOP:~$ cd C:\Users\Hudson\Desktop\Rake\SportBukkit-master
bash: cd: C:UsersHudson: No such file or directory