相关疑难解决方法(0)

如何在Git中规范化工作树行结尾?

我克隆了一个存在不一致行结尾的存储库.我添加了一个.gitattributes为我想要规范化的文件设置text属性.现在,当我提交更改时,我收到消息:

warning: CRLF will be replaced by LF in FILE.
The file will have its original line endings in your working directory.
Run Code Online (Sandbox Code Playgroud)

如何让git为我标准化我的文件的工作副本?我希望git能够规范化整个工作树.

git line-endings gitattributes

57
推荐指数
3
解决办法
2万
查看次数

bash中两个数组的比较/差异

是否有可能在bash中取两个数组的差异.
如果你可以建议我这样做的话会非常棒.

代码:

Array1=( "key1" "key2" "key3" "key4" "key5" "key6" "key7" "key8" "key9" "key10" )
Array2=( "key1" "key2" "key3" "key4" "key5" "key6" ) 

Array3 =diff(Array1, Array2)

Array3 ideally should be :
Array3=( "key7" "key8" "key9" "key10" )
Run Code Online (Sandbox Code Playgroud)

感谢您的帮助.

arrays bash diff compare

46
推荐指数
6
解决办法
7万
查看次数

bash中的数组交集

你如何比较bash中的两个数组来找到所有相交的值?

假设:
array1包含值1和2,
array2包含值2和3

结果我应该回来2.

我自己的答案,由于声誉不佳我无法发布:

for item1 in $array1; do
    for item2 in $array2; do
        if [[ $item1 = $item2 ]]; then
            result=$result" "$item1
        fi
    done
done
Run Code Online (Sandbox Code Playgroud)

我也在寻找替代解决方案.

bash

16
推荐指数
3
解决办法
1万
查看次数

在 shell 脚本中获取 2 个数组中的公共值

我有一个

array1 = (20,30,40,50)
array2 = (10,20,30,80,100,110,40)
Run Code Online (Sandbox Code Playgroud)

我必须从数组 3 中的这 2 个数组中获取公共值,例如:

array3 = (20,30,40) 
Run Code Online (Sandbox Code Playgroud)

按升序排列。

unix sorting bash shell awk

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

数组中的Bash检查元素用于另一个数组中的元素

我找到了这个很酷的Bash函数,用于检查数组是否包含一个元素:

CONTAINS_ELEMENT(){
  local e
  for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
  return 1
}
Run Code Online (Sandbox Code Playgroud)

以下是它的用法示例:

if CONTAINS_ELEMENT $element "${array[@]}"; then
... 
fi
Run Code Online (Sandbox Code Playgroud)

我的问题是:有没有办法重写这个函数,以便它可以检查数组中的任何值是否等于其他数组的任何值,而不只是检查一个单独的值,因为它正确吗?

arrays bash function

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

标签 统计

bash ×4

arrays ×2

awk ×1

compare ×1

diff ×1

function ×1

git ×1

gitattributes ×1

line-endings ×1

shell ×1

sorting ×1

unix ×1