I'm in the process of moving over to my new laptop. I run into an issue where a shell script (that worked under gentoo) now no longer works. Here's the error foo.sh: 18: pushd: not found Since I'm running this as sh foo.sh, I turn on debugging wit
Have you ever been frustrated with perfectly valid bash syntax being highlighted as incorrect in vim? Like this:
#!/bin/sh
foo=$(ls /tmp)
$() is a perfectly valid, nay preferred substitute for backticks. The problem is that vim is deciding this is pure old bourne shell instead of whatever else we'd like it to be. If you change the shebang to #!/bin/bash and re-edit the file, then the error markings go away. But maybe you're writing for the nebulous POSIX shell, not bash nor sh. Or maybe you just don't care and you don't want vim complaining that you're using bashisms even though your shebang says sh. You can set the defaults so that it reflects your system and preferences. It's all there in :help sh.vim.
If you use a VOIP provider for PSTN calls, you will be able to relate to the frustratingly boring caller ID names that get passed down to you. Very infrequently do I get anything better than a city name. Even if you have a direct PSTN connection into Asterisk, you may find the caller ID names from cell phone users (maybe just about everyone that calls you) are less than precise. Here's a solution.
We want to store alternative names in some kind of database that Asterisk can access when a call comes in. AstDB is perfect for this. We also want to leave things unchanged if we haven't manually stored a name for this number. The following will do the trick:
Set(CALLERID(name)=${IF(${DB_EXISTS(cid/${CALLERID(num)})}?${DB(cid/${CALLERID(num)})}:${CALLERID(name)})})
Now, we just need a way to update the database with names. At first I had grandiose ideas of an AJAX-enabled website that shows you the last few CDR records and lets you edit the names with a spiffy in-place editor. You could still accomplish it, but in the end I came up with a much simpler if less elegant solution. At least, it's simpler if you use the terminal all the time like I do. Put this script in your path:
#! /bin/sh
# usage: $0 number "name"
user=`username`
host=falcon
exec ssh $host asterisk -rx \'database put cid \"$1\" \"$2\"\'
Combine this with jabber notification as I've discussed before, and a little cut & paste from your jabber window, and updating names is cake.
I discovered a very strange bug today with OS X's Bourne shell. If you have OS X, give this a try:
/bin/sh -c 'echo -n bug'
This is what you should see:
$ /bin/sh -c 'echo -n bug'
bug$
This is what I see:
$ /bin/sh -c 'echo -n bug'
-n bug
$
In other words, it's ignoring the -n option. It works fine in bash, it's only sh that's broken. It gets better though. If you're using iTerm instead of Terminal.app, it works fine. I have combed through the environment, the locale settings, the terminal emulation, and I can't account for it. I've tried ssh from a linux box which behaves the same as Terminal.app (broken). Who knows what black magic iTerm is invoking.
So I replaced my bash and sh with the ones from MacPorts:
sudo port install bash
sudo mv /bin/bash /bin/bash.old
sudo mv /bin/sh /bin/sh.old
sudo ln /opt/local/bin/bash /bin/bash
sudo ln /opt/local/bin/bash /bin/sh
While you're at it, feel free to
sudo port install coreutils +default_names
Problem solved. Very odd, though. abcde uses echo -n heavily, which breaks in all sorts of ugly ways before this fix. This patch causes abcde to use /bin/bash instead of /bin/sh:
Index: abcde-2.3.3/abcde
===================================================================
--- abcde-2.3.3.orig/abcde 2007-12-07 18:46:36.000000000 -0700
+++ abcde-2.3.3/abcde 2007-12-07 20:57:17.000000000 -0700
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
# Copyright (c) 1998-2001 Robert Woodcock <rcw@debian.org>
# Copyright (c) 2003-2005 Jesus Climent <jesus.climent@hispalinux.es>
# This code is hereby licensed for public consumption under either the
Index: abcde-2.3.3/cddb-tool
===================================================================
--- abcde-2.3.3.orig/cddb-tool 2007-12-07 20:56:49.000000000 -0700
+++ abcde-2.3.3/cddb-tool 2007-12-07 20:57:19.000000000 -0700
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
# Copyright (C) 1999 Nathaniel Smith <njs@uclink4.berkeley.edu>
# Copyright (C) 1999, 2000, 2001 Robert Woodcock <rcw@debian.org>
Speaking of abcde, here's a patch to get rid of an unrelated bug in 2.3.3:
Index: abcde-2.3.3/abcde
===================================================================
--- abcde-2.3.3.orig/abcde 2005-08-25 16:43:27.000000000 -0600
+++ abcde-2.3.3/abcde 2007-12-07 18:46:36.000000000 -0700
@@ -1946,7 +1946,7 @@
FILEPATH=$(find "$FILEPATH" | grep "/$REALTRACKNUM ");
# If the file exists, copy it
if [ -e "$FILEPATH" ] ; then
- nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG" $REDIR
+ nice $READNICE $CDROMREADER "$FILEPATH" "$FILEARG"
else
false
fi ;;
Finally I have abcde at my fingertips again. There's no replacement for abcde when it comes to ripping CDs.





