From owner-freebsd-questions@FreeBSD.ORG Wed Dec 10 06:41:04 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 163E116A4CE for ; Wed, 10 Dec 2003 06:41:04 -0800 (PST) Received: from munk.nu (mail.munk.nu [213.152.51.194]) by mx1.FreeBSD.org (Postfix) with ESMTP id CE6B643D13 for ; Wed, 10 Dec 2003 06:41:00 -0800 (PST) (envelope-from munk@munk.nu) Received: from munk by munk.nu with local (Exim 4.24; FreeBSD) id 1AU5WN-000LJX-16 for freebsd-questions@freebsd.org; Wed, 10 Dec 2003 14:40:59 +0000 Date: Wed, 10 Dec 2003 14:40:58 +0000 From: Jez Hancock To: FreeBSD Questions List Message-ID: <20031210144058.GA81732@users.munk.nu> Mail-Followup-To: FreeBSD Questions List Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i Subject: sed from a shell script - invalid command code X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Dec 2003 14:41:04 -0000 I'm trying to get the following Bourne shell script to output a list of all users on the server with the exception of those listed in the $ignore_users variable: -snip- #!/bin/sh sed=/usr/bin/sed passwd_file=/etc/passwd ignore_users="root|toor|daemon|operator|bin|tty|kmem|games|news|man|smmsp|bind|uucp|xten|pop|nobody|mysql|www|sshd|ftp|cyrus" cmd="$sed -E -e '/^(#|$ignore_users)/d' -e 's/:.*//' $passwd_file" users=`cmd` echo $users -snip- However when I run this code it returns: sed: 1: "'/^(#|root|toor|daemon| ...": invalid command code ' How can I get this code to work? If I echo out the contents of $cmd it looks as it should do: /usr/bin/sed -E -e '/^(#|root|toor|daemon|operator|bin|tty|kmem|games|news|man|smmsp|bind|uucp|xten|pop|nobody|mysql|www|sshd|ftp|cyrus)/d' -e 's/:.*//' /etc/passwd and if I execute that command I get the desired result - I'm just having trouble getting the results of the command into a variable. TIA -- Jez Hancock - System Administrator / PHP Developer http://munk.nu/ http://jez.hancock-family.com/