-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat styleguide #62
Feat styleguide #62
Conversation
@dhxgit @killermoehre could I get your opinions here? |
A note about the vim settings/indentation: these are the current settings used by upstream. We probably fuck up compatibility if we change them. |
## Escaping | ||
We don't want dirty escaping for variables in `echo`, we should prefer printf in these cases, here is a bad example: | ||
```bash | ||
echo -e "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", ATTR{address}==\"$2\", ATTR{dev_id}==\"0x0\", ATTR{type}==\"1\", KERNEL==\"eth*\", NAME=\"$1\"" >> $UDEVFILE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is unfair to compare a double-quoted string containing double-quotes with a single-quoted string containing double-quotes.
Here is a better comparison:
echo 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="'"$2"'", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="'"$1"'"' >> $UDEVFILE
printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="%s"\n' "$2" "$1" >> $UDEVFILE
In this case I would prefer the echo.
The difference in the for-loops is a consequence of the different types you iterating over. You have either a list of strings or on the other hand real integers. Using |
👍 discussed on IRC, c loops are prefered for intergers. this is a working draft and should be extended from time to time. |
I would like to discuss a few guidelines for our shell code. This stuff is based on the questions occurred during #59