shell 没有vim/vi 命令怎么办

由于经常在容器中有一些debug的操作,想要编辑文件,却又发现 一无所有(没有 vim/vi 编辑命令)。解决办法可能是去安装,但下载需要时间等待,且下载的工具使用也不是很频繁。所以换个思路,用其他基础的命令替代下。

cat EOF 常用方法

1
2
3
4
5
# cat <<EOF > cat_test.sh
> #!/bin/bash
> echo "no vim/vi"
> echo "But ... cat"
> EOF

可以用 cat cat_test.sh 核验下内容和格式是否正确;如果原文件存在且有内容,会直接 覆盖

追加 内容

1
2
3
4
# cat <<EOF >> cat_test.sh
> #!/bin/bash
> echo "new add context"
> EOF

cat交互模式下的使用

1
2
3
# cat > cat_in.sh
#!/bin/bash
echo "by cat."

ctrl + d 结束输入


✍TIP

  1. 直接清空文件: >cat_test.sh

  2. 其实可以用其他字符来代替EOF,它也只是个标识符而已!

Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2019-2024 John Doe
  • Visitors: | Views:

请我喝杯咖啡吧~