我正在尝试运行一些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
因此,它实际上并不执行登录,
我启动了cygwin的mintty,并运行了以下命令:
~$ # here, we are in cygwin/bash
~$ printf "\e]0;cygwin\7"
~$ # Now I see "cygwin" on mintty's title
~$ wsl
~$ # now, we are in wsl/bash/debian
~$ printf "\e]0;wsl\7"
~$ # No change in mintty's title
wsl = Linux的Windows子系统
解决
我发现这个基于mintty的
在linux上向文件输出巨大的文本(约500 KB)时很难做到这一点。文本包含空格、特殊字符和其他.获取错误/bin/sh :参数列表太长
#!/bin/bash
txt="---huge text separated by line and containing special characters---"
echo $txt
或
#!/bin/bash
txt="---huge text separated by line and containing special characters---"
echo $txt >> filename.tx
我正在尝试将数据导入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
我有一个程序,它接受单个规则文件形式的一组规则。
当我的程序认为满足其中一个条件时,我会将与该条件相关联的命令块视为需要执行的独立bash脚本。我不想将这些命令存储在文件中,因为这会留下一个不受欢迎的攻击向量。是否有一种方法可以将bash命令作为一个单独的组提供给以行分隔的bash命令列表?我希望if条件和bash脚本中的其他内容能够正确运行,而不仅仅是单独执行每一行。
规则文件示例:
if CONDITION
some nice
bash commands
pkill some process
./launching something!
endif
当条件为真时,我希望能够将这四行bash
我是Linux新手。我正在尝试创建一个脚本来打印某些内容并启动一个关机命令。这是我的剧本:
#!/bin/bash
echo Hello WOOOOORRRRRLLLLDDDDDDD
echo sudo poweroff
每次我试图运行我的脚本,使用
chmod +x Hello World BASH
或者。/你好,世界巴什
但是,我收到以下错误消息:
chmod: cannot access 'Hello': No such file or directory
chmod: cannot access 'World': No such file o
不知何故,我似乎在文件名中生成了带有回车(\r)的文件:
$ ls -1 tri-rods.tm.dat*
tri-rods.tm.dat
'tri-rods.tm.dat'我试着用"\r“来查找,但什么也找不到:$ find . -type f -name '*\r'我如何列出/查找和删除这些文件?加上"?“对于文件名工作,所以我可以一个一个地删除它们,但我更喜欢一个更一般的方式。注意:我正试图通过Cygwin/git-bash/Windows子系统在Windows上实现Linux,所以可能有些命令不能像预期的那样工作。\r'
$ ls
为什么这个命令行工作:
$ 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
与
我执行以下操作是为了使历史更加合理(例如,在排除故障时,查看何时运行命令是相当关键的)
shopt -s histappend; # Append commands to the bash history (~/.bash_history) instead of overwriting it # https://www.digitalocean.com/community/tutorials/how-to-use-bash-history-commands-and-expansions-on-a-linux-vps
export PROMPT_COMMAND="history
我希望将windows服务器路径(\100.100.0.0\aaa\bbb\ccc)替换为linux路径/foo/bar/在文件夹(/xxx/yyy/zzz/)中所有.txt文件中出现的所有事件。
为此,我做了一个循环,似乎在bash或tcsh上都不起作用(使用foreach)。
#!/bin/bash
FILES="/xxx/yyy/zzz/*.txt"
for f in $FILES
do
sed -i 's+\\100.100.0.0\aaa\bbb\ccc\+/foo/bar/+g' $f
done
我得到的错误如下:
sed: -e e
我正在为linux终端使用Windows子系统,每次打开一个新终端时,我都会收到以下错误消息:
-bash: /usr/bin/tclsh: No such file or directory
-bash: export: _moduleraw: not a function
-bash: export: module: not a function
user@User-Laptop:~$
我检查了我的.bashrc文件,它似乎没有任何叫做module或moduleraw的东西。(我确实为代码添加了一些额外的导出语句。)
关于tclsh的第一个错误很可能是我在试图更改为tcsh时错误地输入了t