I am currently reading a very old reference from O'Reilly: Sed and Awk 2nd Edition reprinted in 2000. So far, it's a solid read and still very relevant. I'd highly recommend this to anyone.
The only problem I have with this book is that I had to resort to bourne shell to get my examples to work since bash wasn't ubiquitous when the book was written.
So, when I was trying to follow the book example, I get the error in bash on my latest Ubuntu Server distro.
I tried to use a regular expression that looked for any line containing the string, "book" in the bookworks file. It is not my ultimate goal to correctly extract all lines with the string "book" yet as I was following the book examples, which will show me the correct form.
I tried the following command in bash:
I get the following error in bash:
But when I tried the command after switching over to bourne shell, I get no error, and it gave me the output I expected like the one in the book examples. Can someone please tell me why is this happening? I'd like to know what metacharacters are causing this and how I can escape it in Bash? I wish there is a third edition of this book that covers REGEX in bash.
That is because of bash's history expansion. It tries to expand the exclamation mark. Try switching it off first:
Then it should work.
You could also escape the exclamation mark(s):
Or use single quotes but in your example they use double quotes in order to use a single quote in the expression. You could make a combination of a string that is part in single quotes, followed by a part in double quotes:
Last edited by Scrutinizer; 03-20-2013 at 12:55 PM..
This User Gave Thanks to Scrutinizer For This Post:
That it's willing to expand history !'s inside quotes is one of the very few things that really enrages me about bash... A character that expands when quoted and doesn't when not, but only at certain times and not others, seems very hacky.
Hello, everyone. I'm currently trying to write a command system for a Minecraft server using screen.
Here are the scripts I'm currently using.
0.sh
#!/bin/bash
screen -S Test114 -dm java -Xmx4G -jar server.jar nogui
1.sh
#!/bin/bash
args="$@"
args2="${args@Q}"
#args3=`printf '%q\n'... (2 Replies)
I am trying to find files using the following by using simple bash script:
if -2014 ]]; then echo "yes";fi
What I need to find are any files with date 08-**-2014 so August 2014 any files.
I can use if -2014 ]]; then echo "yes";fi
That works fine. How do I get files beginning with 08... (1 Reply)
Please forgive me if this is the wrong forum. I want to execute some one liners with the groovy programming language and I'm having trouble escaping the special characters to accommodate bash.
Here is one of the lines that is giving me trouble:
groovy -e "(new... (1 Reply)
I have a file which contains a list of paths separated by a new line character.
e.g
/some/path/to/a/file.png
/some/path to/another/file.jpeg
/some path/to yet/another/file
Notice that these paths may contain metacharacters, the spaces for example are also not escaped.
If I wanted... (5 Replies)
for (( i=1; i<=3; i++ )); do
for (( j=1; j<=3; j++ )); do
for (( k=1; k<=3; k++ )); do
echo $i$j$k
done
done
done
Will the above code work on a BOURNE shell?
As far as my understanding is, if I am writing the above code in a file..say lol.sh and then running it through the terminal using... (7 Replies)
Here's the input:
alpha, numeric or alphanumeric string ("line 1 string")
numeric string ("line 2 string")
numeric string ("line 3 string")
numeric string ("line 4 string")
...
where
- each numeric string is in a pattern that can be matched with RE but
- there can be any number of... (2 Replies)
I have a script that start out with this:
#!/sbin/sh
Several things run.
However I cannot get:
shopt -s nullglob
to run in Bourne. I get:
shopt: not found
So within the main script (after #!/sbin/sh at the top) I start bash with:
bash
and try to run what I need with:
shopt -s... (2 Replies)
Hi All,
I know difference between shell(s) we are using, ie. sh, bash etc.
But while writing shell script, is there any difference which shell I am using. and if yes, what are they? (4 Replies)
I have the following situation
============
export DirectoryName=/tmp/xyz
if ; then
some_new_env=$DirectoryName"/*"
=======================
I tried all the ways of escaping the '*', but still the shell seems to expand the '*' character. I want some_new_env to contain "/tmp/xyz/*"
... (7 Replies)
hi there. i have a simple bash script that reads a word from a text file
one at a time, and if a '*' character is encountered, it prints a message.
however it doesn't work as i expected. :o what am i doing wrong here?
thanks very much for the help :)
for word in `cat $DOC`
do
if... (18 Replies)