如何使用Bash迭代文本文件的每一行?
使用此脚本:
echo "Start!"
for p in (peptides.txt)
do
echo "${p}"
done
Run Code Online (Sandbox Code Playgroud)
我在屏幕上看到这个输出:
Start!
./runPep.sh: line 3: syntax error near unexpected token `('
./runPep.sh: line 3: `for p in (peptides.txt)'
Run Code Online (Sandbox Code Playgroud)
(后来我想做一些$p比输出到屏幕更复杂的事情.)
环境变量SHELL是(来自env):
SHELL=/bin/bash
Run Code Online (Sandbox Code Playgroud)
/bin/bash --version 输出:
GNU bash, version 3.1.17(1)-release (x86_64-suse-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
Run Code Online (Sandbox Code Playgroud)
cat /proc/version 输出:
Linux version 2.6.18.2-34-default (geeko@buildhost) (gcc version 4.1.2 20061115 (prerelease) (SUSE Linux)) #1 SMP Mon Nov 27 11:46:27 UTC 2006
Run Code Online (Sandbox Code Playgroud)
文件peptides.txt包含:
RKEKNVQ
IPKKLLQK
QYFHQLEKMNVK …Run Code Online (Sandbox Code Playgroud) 我知道有Alt+ Enter组合将单个String提取到字符串资源.但我想知道有什么东西可以将我的项目的所有字符串提取到字符串资源中吗?
如果我制作其中一个,Android工作室也不会将相同的String制作成字符串资源.
String s = "Hello World";
String s2 = "Hello World";
Run Code Online (Sandbox Code Playgroud)
例如.我将"Hello World"创建为字符串资源,另外还在项目中同样保存硬编码.
String s = getString(R.string.helloworld);
String s2 = "Hello World";
Run Code Online (Sandbox Code Playgroud)
如果有人知道这样的事情.
你能告诉我如何迭代列表中的项目可以包含空格吗?
x=("some word", "other word", "third word")
for word in $x ; do
echo -e "$word\n"
done
Run Code Online (Sandbox Code Playgroud)
如何强制输出:
some word
other word
third word
Run Code Online (Sandbox Code Playgroud)
代替:
some
word
(...)
third
word
Run Code Online (Sandbox Code Playgroud) 我有一个列表参数需要一个一个地传递给另一个命令,因为该命令一次只接受一个参数,我可以使用任何 shell 管道吗?先感谢您。
例如,
$ ls -al | awk '{print $9}'
Run Code Online (Sandbox Code Playgroud)
该命令将返回一个文件夹名称列表,然后我需要将这些名称作为参数发送给 anther 命令,该命令仅接受每次执行的命令。