Bash script and /bin/bash^M: bad interpreter: No such file or directory [duplicate]
Run following command in terminal sed -i -e ‘s/\r$//’ scriptname.sh Then try ./scriptname.sh It should work.
Run following command in terminal sed -i -e ‘s/\r$//’ scriptname.sh Then try ./scriptname.sh It should work.
Use: find . 2>/dev/null > files_and_folders This hides not just the Permission denied errors, of course, but all error messages. If you really want to keep other possible errors, such as too many hops on a symlink, but not the permission denied ones, then you’d probably have to take a flying guess that you don’t … Read more
Move the quotes. Just don’t quote the *. Probably also good not to quote the ~. go() { cd ~/”project/entry ${1}”* } That being said if this matches more than one thing cd will use the first match and ignore all the other matches.
You need to do shopt -s expand_aliases in the script in addition to sourcing ~/.bashrc.
You can use sed for this. For example: $ sed -n ‘/Feb 23 13:55/,/Feb 23 14:00/p’ /var/log/mail.log Feb 23 13:55:01 messagerie postfix/smtpd[20964]: connect from localhost[127.0.0.1] Feb 23 13:55:01 messagerie postfix/smtpd[20964]: lost connection after CONNECT from localhost[127.0.0.1] Feb 23 13:55:01 messagerie postfix/smtpd[20964]: disconnect from localhost[127.0.0.1] Feb 23 13:55:01 messagerie pop3d: Connection, ip=[::ffff:127.0.0.1] … How it works … Read more
Try redirecting stderr to stdout and using $() to capture that. In other words: VAR=$((your-command-including-redirect) 2>&1) Since your command redirects stdout somewhere, it shouldn’t interfere with stderr. There might be a cleaner way to write it, but that should work. Edit: This really does work. I’ve tested it: #!/bin/bash BLAH=$(( ( echo out >&1 echo … Read more
You can use a C-style for loop: foo=string for (( i=0; i<${#foo}; i++ )); do echo “${foo:$i:1}” done ${#foo} expands to the length of foo. ${foo:$i:1} expands to the substring starting at position $i of length 1.
There are several questions/issues here, so I’ll repeat each section of the poster’s text, block-quoted, and followed by my response. What’s the preferred syntax, and why? Or are they pretty much interchangeable? I would say that the $(some_command) form is preferred over the `some_command` form. The second form, using a pair of backquotes (the “`” … Read more
shuf -i 2000-65000 -n 1 Enjoy! Edit: The range is inclusive.
The Maven Help Plugin is somehow already proposing something for this: help:evaluate evaluates Maven expressions given by the user in an interactive mode. Here is how you would invoke it on the command line to get the ${project.version}: mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate \ -Dexpression=project.version As noted in the comments by Seb T, to only print the version … Read more