Fedora bash program not working properly

。_饼干妹妹 提交于 2019-12-31 05:35:52

问题


I am trying to just run a simple bash command but i'm not sure what i'm misssing

#!/bin/bash
$person = Craig Baiey
echo $person
echo '$person'
echo "$person"

everytime I run it i get an error line 2: =: command not found

$person


回答1:


Space is the problem around =. It should be:

person="Craig Baiey"
  • You don't assign into variable with $ in name.
  • And quotes are also required there.

btw this line won't print the variable's value:

echo '$person'

As shell won't expand it due to presence of single quotes. It will instead literal $person




回答2:


Remove the $ before person on line 2:

#!/bin/bash
person="Craig Baiey"
echo $person


来源:https://stackoverflow.com/questions/22722709/fedora-bash-program-not-working-properly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!