我是Shell-Script World的新手,我试图找到解决问题的方法。
我有以下脚本:
HSLarray= $(grep -E '((HSL|hsl)+(\()+(.)+(\));)' $1 )
for i in "${HSLarray[@]}"
do
echo $i
done
(此时脚本没有真正的功能) 它应该在SCSS文件(或任何文件)中搜索Pattern" hsl(*);",但它会以错误退出:
./search_HSL.sh: line 1: color:: command not found
如果我使用上面的grep作为普通命令,它会给出以下输出:
$ grep -E '((HSL|hsl)+(\()+(.)+(\));)' scss/template/sass/_base.scss
color: hsl($button_primary_hue, 0%, 67%);
border: $standard_border_width dashed hsl($primary_hue + 1, 95%, 51%);
color: hsl($button_primary_hue, 0%, 40%);
color: hsl($button_primary_hue, 0%, 67%);
color: hsl($button_primary_hue, 0%, 0%);
color: hsl($button_primary_hue, 0%, 67%);
background-color: hsl($menuButton_hue, 0%, 100%);
background: hsl($menuButton_hue, 0%, 100%);
color: hsl($menuButton_hue, 0%, 67%);
border: $standard_border_width solid adjust-color(hsl($splitBar_hue - 12, 57%, 46%), $saturation: $splitBar_saturation, $lightness: $splitBar_lightness);
border: $standard_border_width solid adjust-color(hsl($splitBar_hue - 12, 57%, 46%), $saturation: $splitBar_saturation, $lightness: $splitBar_lightness);
border-right: $standard_border_width solid adjust-color(hsl($splitBar_hue - 12, 57%, 46%), $saturation: $splitBar_saturation, $lightness: $splitBar_lightness);
border-left: $standard_border_width solid adjust-color(hsl($splitBar_hue - 12, 57%, 46%), $saturation: $splitBar_saturation, $lightness: $splitBar_lightness);
background-color: adjust-color(hsl($primary_hue, 95%, 86%), $saturation: $sectionStack_saturation, $lightness: $sectionStack_lightness);
adjust-color(hsl($sectionStack_primary_hue, 0%, 67%), $saturation: $sectionStack_saturation, $lightness: $sectionStack_lightness) 100%)) padding-box);
adjust-color(hsl($sectionStack_primary_hue, 95%, 85%), $saturation: $sectionStack_saturation, $lightness: $sectionStack_lightness) 100%)) padding-box);
adjust-color(hsl($sectionStack_primary_hue + 1, 25%, 69%), $lightness: $sectionHeader_border_lightness) 100%)) padding-box);
color: hsl(212, 53%, 60%);
// color: hsl(212, 53%, 60%);
border: $standard_border_width solid hsl($primary_hue + 2, 34%, 51%);
right: $standard_border_width solid hsl($secondary_hue + 1, 63%, 83%);
left: $standard_border_width solid hsl($secondary_hue - 2, 36%, 78%);
background-color: hsl($secondary_hue, 100%, 92%);
bottom: $standard_border_width dotted hsl($secondary_hue + 7, 63%, 77%);
top: $standard_border_width dotted hsl($secondary_hue + 7, 63%, 77%);
background-color: hsl($secondary_hue + 2, 68%, 89%);
bottom: $standard_border_width dotted hsl($secondary_hue + 7, 63%, 77%);
top: $standard_border_width dotted hsl($secondary_hue + 7, 63%, 77%);
bottom: $standard_border_width solid adjust-color(hsl($filterBuilder_bracketBorder_hue - 12, 57%, 46%), $saturation: $filterBuilder_bracketBorder_saturation, $lightness: $filterBuilder_bracketBorder_lightness);
left: $standard_border_width solid adjust-color(hsl($filterBuilder_bracketBorder_hue - 12, 57%, 46%), $saturation: $filterBuilder_bracketBorder_saturation, $lightness: $filterBuilder_bracketBorder_lightness);
top: $standard_border_width solid adjust-color(hsl($filterBuilder_bracketBorder_hue - 12, 57%, 46%), $saturation: $filterBuilder_bracketBorder_saturation, $lightness: $filterBuilder_bracketBorder_lightness);
background-color: hsl($primary_hue - 3, 100%, 87%);
color: hsl($primary_hue + 2, 0%, 100%);
hsl($primary_hue + 2, 15%, 75%) 100%)));
border-top: 2px dotted hsl($primary_hue + 2, 100%, 73%);
border-right: 2px dotted hsl($primary_hue + 2, 100%, 73%);
adjust-color(hsl($listGrid_headerButton_disabled_hue - 6, 88%, 90%), $saturation: $listGrid_headerButton_disabled_saturation, $lightness: $listGrid_headerButton_disabled_lightness) 100%)) padding-box);
color: hsl($primary_hue, 0%, 67%);
background-color: hsl($secondary_hue, 93%, 88%);
background-color: hsl($primary_hue - 6, 54%, 84%);
background-color: hsl($primary_hue - 6, 54%, 84%);
background-color: hsl($primary_hue - 6, 54%, 84%);
background-color: hsl($primary_hue + 9, 57%, 88%);
color: hsl($primary_hue - 2, 53%, 27%);
所以我认为在输出的第1行中,某些东西逃脱了grep命令并被视为它自己的命令。但是我怎么能阻止这个呢? 我希望每一行都作为数组中的字符串元素。