Shell 脚本读取输入并复制和粘贴
好吧,我想这样做,我正在尝试编写一个脚本,使用此代码询问用户他们想要什么,我可以记录他们的输入。
#!/bin/bash
read inputline
what="$inputline"
echo $what
然后,我有另一个文件放置在该路径 /system/etc/99oc 的其他位置,如下所示
Some text some more text (want user input Pasted Here) more text more text
所以脚本需要能够接受输入并将其粘贴到另一个文档的文本之间。这可能吗?替代品?
感谢您的帮助
编辑 是的,抱歉,这是第二个文件中的每一行,这些行将被复制到
echo "1 '输入在此处'" > /proc/overclock/mpu_opps
echo "2 '输入在此处'" > /proc/overclock/mpu_opps
echo "3 '输入在此处'" > /proc/overclock/mpu_opps
echo "4 '输入在此处'" > /proc/overclock/mpu_opps
echo "5 '输入在此处'" > /proc/overclock/mpu_opps
echo "6 '输入在此处'" > /proc/overclock/mpu_opps
其中“输入在此处”而没有“ ”是应该粘贴输入的位置
也刚刚了解到我可以执行 cp $what
感谢您的帮助
Okay i'm looking to do this i'm trying to write a script that will ask the user what they want using this code i can do that i records their input.
#!/bin/bash
read inputline
what="$inputline"
echo $what
I then have another file that is placed else where at this path /system/etc/99oc which looks like this
Some text some more text (want user input pasted here) more text more text
So the script needs to be able to take the input and paste it in between text in another document. Is this possible? alternatives?
Thank you for any help
Edit
Yes sorry here are each lines in the second file that would be copied into
echo "1 'input goes here'" > /proc/overclock/mpu_opps
echo "2 'input goes here'" > /proc/overclock/mpu_opps
echo "3 'input goes here'" > /proc/overclock/mpu_opps
echo "4 'input goes here'" > /proc/overclock/mpu_opps
echo "5 'input goes here'" > /proc/overclock/mpu_opps
echo "6 'input goes here'" > /proc/overclock/mpu_opps
where 'input goes here' with out the ' ' is where the input should be pasted
also just learned i can do cp $what
Thanks for the help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试一下:
sed
命令将对文件进行适当的更改(对于 GNUsed
)。如果您运行的是 OS X,则需要备份扩展。如果您运行的sed
版本没有-i
,则需要将输出重定向到临时文件并重命名。请务必在测试文件上使用它,以确保它符合您的要求。
Give this a try:
The
sed
command will make the change to the file in place (for GNUsed
). If you're running OS X, a backup extension is required. If you're running a version ofsed
that doesn't have-i
, you'll need to redirect the output to a temporary file and rename it.Be sure and use this on a test file to make sure it does what you want.
是的,这可以通过
sed
或awk
之类的东西来实现,但我们需要一些东西来了解(希望将用户输入粘贴到此处)
应该去。即,它是否总是插入到以“Some”开头的行中的第 6 个和第 7 个单词之间,等等。Yes, this is possible with something like
sed
orawk
but we would need something to key off of to know where(want user input pasted here)
should go. I.e., will it always be inserted between the 6th and 7th word in the line that starts with 'Some', etc.使用 sed 可以轻松完成。
无论使用什么操作(插入、添加或交换),语法都将保持不变:
检查 http://en.kioskea.net/faq/1454-inserting-text-in-a-file 获取更多帮助。
Can be easily done with sed.
Whatever operation (insertion, addition or exchange) is used, the syntax will remains the same:
Check http://en.kioskea.net/faq/1454-inserting-text-in-a-file for more help.