我使用以下内容来缩进configure脚本的输出:
./configure | sed "s/^/ /"
Run Code Online (Sandbox Code Playgroud)
现在我想重用管道后面的部分,所以我不必写
./configure | sed "s/^/ /"
make | sed "s/^/ /"
make install | sed "s/^/ /"
Run Code Online (Sandbox Code Playgroud)
我试过把sed变量放在这样一个变量中:
indent=sed "s/^/ /"
Run Code Online (Sandbox Code Playgroud)
然后呢
./configure | indent
Run Code Online (Sandbox Code Playgroud)
但那不起作用 - 我怎样才能做到这一点?
我在一个迷你项目中工作:"我自己的命令解释器(壳)",像Bash shell或Sh shell.直到现在它可以执行每个预定义的命令,如ls,ps,pwd,date.除此之外,我已经实现了一些其他操作,如输入重定向(<),输出重定向(>),PIPE(|)功能.除此之外,我已经实现了自己的用户命令,如pid,ppid,quit,hist.
vvdnlt208@vvdnlt208-Vostro-3446:~/project/Vector/sourabh/unix/proj2$ ./my_sh
<1 SOURABH> ls
a cd.c execute.o inredir.c main.o multiexec.o my_sh sh.c sigign.c test.c
addhist.c dir header.h inredir.o Makefile mypipe.c outredir.c showhist.c sigign.o tetest.c
addhist.o execute.c inredir main.c multiexec.c mypipe.o outredir.o showhist.o test2.c
<2 SOURABH> ps
PID TTY TIME CMD
6120 pts/10 00:00:01 bash
6510 pts/10 00:00:00 grep
6512 pts/10 00:00:00 grep
6514 pts/10 00:00:00 grep
6516 pts/10 00:00:00 grep
7772 pts/10 00:00:00 my_sh
7774 pts/10 00:00:00 ps
<3 SOURABH> pwd
/home/vvdnlt208/project/Vector/sourabh/unix/proj2
<4 SOURABH> date
Fri …Run Code Online (Sandbox Code Playgroud) 我现在在OSX终端,并尝试将大量文件从中移动~/Desktop/dir/到~/Desktop/dir/dir2.
命令
mv *.* ~/Desktop/dir/dir2
Run Code Online (Sandbox Code Playgroud)
不起作用.
我真的是Shell Bash脚本的新手。对于用户输入的给定任意数字,我需要在一行上按升序打印数字。
#!/bin/bash
declare nos[5]=(4 -1 2 66 10)
# Prints the number befor sorting
echo "Original Numbers in array:"
for (( i = 0; i <= 4; i++ ))
do
echo ${nos[$i]}
done
#
# Now do the Sorting of numbers
#
for (( i = 0; i <= 4 ; i++ ))
do
for (( j = $i; j <= 4; j++ ))
do
if [ ${nos[$i]} -gt ${nos[$j]} ]; then
t=${nos[$i]}
nos[$i]=${nos[$j]}
nos[$j]=$t
fi
done
done
# …Run Code Online (Sandbox Code Playgroud) 在bash(版本3)脚本中,我想保存传递的命令行参数,以便我可以多次迭代它们(使用shift)并可能删除其中的一些.
据我所知,它"$@"首先就像一个数组.
我的第一个冲动是写:
cmdArgs="$@"
然后cmdArgs像任何其他数组一样操纵.
但是,我正在阅读很多答案,其中使用了另一种语法:
read -ra cmdArgs <<<"$@"
为什么?第二种选择更长,不太明显,但似乎是首选.所以为什么?
我需要运行批处理以登录到服务器,进入sudo su - username并运行特定命令。
我尝试下面的代码:
putty username@servername -pw password -m myshell.sh
Run Code Online (Sandbox Code Playgroud)
myshell.sh:
#!/bin/sh
sudo su - username
cd to particular folder
then tail a file
Run Code Online (Sandbox Code Playgroud)
我进入sudo,但此后脚本卡住,直到我注销。
在https://github.com/giorgiosironi/erlang-2pc/blob/master/nodes.erl#L95中,我产生了3个进程,这些进程在算法结束后终止(或者我认为:它们的函数返回).我认为start/0函数也已终止.
我开始执行这个函数:
erl -noshell -run nodes test_commit -noshell
执行该函数后,我得到了我预期的输出:
<0.30.0> - As coordinator added cohort: <0.31.0>
<0.31.0> - Will propose: yes
<0.32.0> - Will propose: yes
<0.30.0> - As coordinator added cohort: <0.32.0>
<0.30.0> - As coordinator, 1st phase trying to commit
<0.31.0> - Queried by coordinator
<0.32.0> - Queried by coordinator
<0.30.0> - As coordinator received a yes
<0.30.0> - As coordinator received a yes
<0.30.0> - As coordinator, 2nd phase
<0.31.0> - COMMIT!
<0.32.0> - COMMIT! …
有人可以向我解释一下,在korn shell中,有什么区别:
ANOTHER_VAR=${SOME_VAR}
Run Code Online (Sandbox Code Playgroud)
和
ANOTHER_VAR=$SOME_VAR
Run Code Online (Sandbox Code Playgroud)
我遇到了这些类型的声明,看不出有什么不同......
谢谢!
我想做这个
xmllint --xpath "//filestodelete[filename = somename]/text()" #filestodelete#
Run Code Online (Sandbox Code Playgroud)
和filestodelete是XML类型的BPEL变量
但它不起作用
怎么做> ??
我正在使用Mac OSX,我正在尝试创建一个脚本,该脚本将ssh user@host随后从虚拟服务器中更改工作目录(cd).
谷歌说,这ssh -t user@host "command goes here"将允许这样,但当我输入cd /my/path它说没有这样的目录.它还迫使我退出服务器.实现这一目标的最佳,最简单的方法是什么?