小编Mil*_*vić的帖子

使用 VIM 编辑器将第一个评论放入 yaml 文件时禁用自动选项卡?

更改前的文本示例:

First line
Second line
Third line
Run Code Online (Sandbox Code Playgroud)

当您在一行上添加注释时,它将自动跳到该行一次。

每次您从 ESCAPE 模式切换到 INSERT 模式以获取第一个注释时,都会发生这种情况。

添加第一条评论 (#)后的文本示例

First line
     #Second line
Third line
Run Code Online (Sandbox Code Playgroud)

在.vimrc中放置什么选项来禁用此行为?我在谷歌上找不到讨论这个主题的文章。谢谢你!

vim vimrc

5
推荐指数
1
解决办法
2388
查看次数

如何将命令的输出作为参数列表传递给脚本?

我想将内容添加到当前目录中每个文件的开头。我需要学习如何一次从当前工作目录中获取所有文件名并将它们作为参数;我不需要通过手动指定每个文件作为脚本的参数来做到这一点。我想将这些新知识用于进一步的脚本。我不需要横向或不同的解决方案。我需要学习如何获取命令 ( ls) 输出并将其作为参数。我尝试过但失败了:

./file-edit.sh $(ls)
./file-edit.sh `ls`
Run Code Online (Sandbox Code Playgroud)

这是我的脚本,它有效:

#!/bin/bash
lineno=2            # Append from line 2 
BAD_ARGS=85         # Error code

string0="###################################################################"
string2="#Description    :"
string3="#Date           :`date +%d-%B-%Y`"
string4="#Author         :Milos Stojanovic"
string5="#Contact:       :https://www.linkedin.com/in/xxx/"
string6="###################################################################"
# Can be any other strings

if [ ! -f $1 ]; then
        echo "Please specify at least 1 filename as an argument!"
        exit $BAD_ARGS
fi

until [ -z  "$1" ]
do
        string1="#Script Name    :$1"
        file=$1;
        sed -i ""$lineno"i $string0\n$string1\n$string2\n$string3\n$string4\n$string5\n$string6" $file
        echo "File "\'$file\'" altered at line …
Run Code Online (Sandbox Code Playgroud)

ls scripting bash arguments

2
推荐指数
1
解决办法
425
查看次数

脚本的命令行选项

$ cat test15.sh  
#!/bin/bash  
# extracting command line options as parameters  
#  
echo  
while [ -n "$1" ]  
do  
    case "$1" in  
    -a) echo "Found the -a option" ;;  
    -b) echo "Found the -b option" ;;  
    -c) echo "Found the -c option" ;;  
     *) echo "$1 is not an option" ;;
esac  
shift  
done  
$  
$ ./test15.sh -a -b -c -d

Found the -a option  
Found the -b option  
Found the -c option  
-d is not an option 
$  
Run Code Online (Sandbox Code Playgroud)

-d …

linux command-line scripting bash

0
推荐指数
1
解决办法
451
查看次数

标签 统计

bash ×2

scripting ×2

arguments ×1

command-line ×1

linux ×1

ls ×1

vim ×1

vimrc ×1