我正在尝试在 Bash 中编写一个未找到的句柄,它执行以下操作:
cd
进入它。$DEV_DIR
,`cd 进入它。现在我有这样的事情:
export DEV_DIR=/Users/federico/programacion/
function command_not_found_handle () {
if [ -d $1 ]; then # the dir exists in '.'
cd $1
else
to=$DEV_DIR$1
if [ -d $to ]; then
cd $to
echo `pwd`
else
echo "${1}: command not found"
fi
fi
}
Run Code Online (Sandbox Code Playgroud)
尽管它似乎在工作(该echo pwd
命令打印了预期的目录),但实际 shell 中的目录并没有改变。
我的印象是,因为这是我.bashrc
的 shell 中的一个函数,所以我不会分叉,我可以这样做,cd
但显然这不起作用。任何有关如何解决此问题的提示将不胜感激。
我一直在尝试编写一个脚本,它将获取当前工作目录,扫描每个文件并检查它是否是.txt文件.然后获取每个文件(这是一个文本文件),并检查它的名称中是否包含下划线,以及是否将下划线更改为连字符.
我知道这是一个很高的命令,但这是我到目前为止的粗略代码:
#!/bin/bash
count=1
while((count <= $#))
do
case $count in
"*.txt") sed 's/_/-' $count
esac
((count++))
done
Run Code Online (Sandbox Code Playgroud)
我想的是,这会将当前工作目录中的文件作为参数并检查每个文件(由$ count表示或文件在"count"处).然后对于每个文件,它将检查它是否以.txt结尾,如果是,它将使用sed将每个下划线更改为连字符.我认为我遇到的一个主要问题是脚本没有从当前工作目录中读取文件.我尝试在运行脚本的命令后包含目录,但我认为它占用了每一行而不是每个文件(因为每行有4个左右的文件).
无论如何,任何帮助将不胜感激!另外,我很抱歉我的代码太糟糕了,我对UNIX很新.
我想拆分像'substring1 substring2 ONCE[0,10s] substring3'这样的字符串。预期结果应该是(使用分隔符“ONCE[0,10s]”):
substring1 substring2
substring3
Run Code Online (Sandbox Code Playgroud)
问题是分隔符中的数字是可变的,例如 'ONCE[0,1s]' 或 'ONCE[0,3m]' 或 'ONCE[0,10d]' 等等。
我怎样才能在 bash 脚本中做到这一点?任何的想法 ?
谢谢
在 bash 中,我可以捕获SIGINT
、SIGKILL
、SIGTERM
等。这使我可以根据程序意外停止的方式做不同的事情。
有没有办法在R中做到这一点?
我需要一个"警报"类型功能来解决错误.我没有使用浏览器并使用javascript作为windows管理目的.如果我不使用浏览器,那么他们是一种查看varibales值的方法吗?
超奇怪,没有?违规代码:
def main():
"""
main function
"""
# Argument handling
args = sys.argv[1:]
if not args:
print "usage is: ...
Run Code Online (Sandbox Code Playgroud)
第三个引用是我得到通常的缩进错误:
>>>Import someScript
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "someScript.py", line 24
"""
^
Run Code Online (Sandbox Code Playgroud)
如果我删除了注释(显然我不想),那么要定义的下一个函数会在其注释的同一位置获得相同的错误.如果我删除函数中的所有注释,则错误消失.
我不明白!为什么期望有缩进?我正在写Komodo编辑部分因为它不会让你混合空格和标签,但只是为了确保我做了一个搜索,当然,没有friggin标签.如果有的话,不管怎么说都没有意义.
什么给,大师?
我有一个像这样的文件列表:
wgEncodeCaltechRnaSeqGm12878R1x75dFastqRep1.fastq.trim.tags.sam
wgEncodeCaltechRnaSeqGm12878R1x75dFastqRep2.fastq.trim.tags.sam
wgEncodeCshlLongRnaSeqGm12878CellPapFastqRd1Rep1.fastq.trim00.tags.sam
wgEncodeCshlLongRnaSeqGm12878CellPapFastqRd1Rep1.fastq.trim01.tags.sam
wgEncodeCshlLongRnaSeqGm12878CellPapFastqRd1Rep1.fastq.trim02.tags.sam
wgEncodeCshlLongRnaSeqGm12878CellPapFastqRd1Rep2.fastq.trim00.tags.sam
wgEncodeCshlLongRnaSeqGm12878CellPapFastqRd1Rep2.fastq.trim01.tags.sam
wgEncodeCshlLongRnaSeqGm12878CellPapFastqRd1Rep2.fastq.trim02.tags.sam
wgEncodeCshlLongRnaSeqGm12878CellPapFastqRd2Rep1.fastq.trim00.tags.sam
wgEncodeCshlLongRnaSeqGm12878CellPapFastqRd2Rep1.fastq.trim01.tags.sam
Run Code Online (Sandbox Code Playgroud)
我想从文件名中删除Rd1,Rd2和.sam stings.使用以下bash脚本,我可以使用两个命令删除Rd1,Rd2和.sam字符串....
for i in $(ls)
do
echo "${i/Rd?/}"
echo "${i/.sam/}"
done
Run Code Online (Sandbox Code Playgroud)
但我想知道如何一步完成两次换人你知道怎么做吗?
谢谢你的时间!
我在ubuntu下的exec()函数有问题.有没有可能回到主程序?
例:
printf("Some instructions at beginning\n");
execlp("ls","ls", "-l", NULL);
// i want to continue this program after exec and see the text below
printf("Other instructions\n");
Run Code Online (Sandbox Code Playgroud) 我似乎无法弄清楚如何在if语句中正确编写正则表达式.我希望它打印出所有带有"结束日期"的行.
NUMBERS包含一个包含以下内容的文本文件:
End Date ABC ABC ABC ABC ABC ABC
05/15/13 2 7 1 1 4 5
04/16/13 4 3 0 1 3 6
03/17/13 6 9 3 8 5 9
02/18/13 8 2 7 1 0 1
01/19/13 1 9 2 2 5 2
12/20/12 7 2 7 1 0 1
Run Code Online (Sandbox Code Playgroud)
以下是我的代码片段,我遇到了以下问题:
if [ -f $NUMBERS ]
then
while read line
do
if [ $line = ^End ]
then
echo "$line"
else
echo "BROKEN!"
break
fi
done …
Run Code Online (Sandbox Code Playgroud) 我的期望脚本中有这样的声明
send "sed -i -e 's/$oldport/$newport/' backup.txt\r"
expect "$ "
Run Code Online (Sandbox Code Playgroud)
但是,我希望首先检查文件 backup.txt 是否存在,如果存在,则对其进行编辑。
我如何实现这一目标?
谢谢