Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is the error I am getting and it's failing because of a variable whose value is supposed to be 2 (I am getting this using a select * from tabel). I am getting spaces in that variable.

+ 0 != 
./setjobs[19]: 0:  not found.

How do I remove all those spaces or a newline from that variable? Can tr, sed, or anything help?

This what I am doing:

set_jobs_count=$(echo  "set heading off;
      select count(*) from oppar_db
      where ( oppar_db_job_name, oppar_db_job_rec ) in ($var) ;" | \

This works as suggested:

| sed 's/[[:space:]]//g'

But I still obtain a value like :

share|improve this question
You can cast a string to an int in the select statement. How that is done depends on database, Sybase, Oracle, MySQL, etc. – bsd Feb 24 '12 at 13:05
how do i do that, i have oracle 9i – munish Feb 24 '12 at 13:11
using sed it's | sed 's/[[:space:]]//g' to collapse whitespace – bsd Feb 24 '12 at 14:06
thanks works up to some extent but still the values of variable comes like set_jobs_count= 2 – munish Feb 24 '12 at 14:37
i got it thanks – munish Feb 24 '12 at 15:14
up vote 9 down vote accepted

You can use tr, as in tr -d '\040\011\012\015', which will remove spaces, tabs, carriage returns and newlines.

share|improve this answer
Is there an advantage of using \040\011\012\015 over [:space:]? – Nick Mar 11 '15 at 2:04
Portability with very old UNIX versions is the only reason I can think of--- old enough that the UNIX version predates POSIX.1. – Kyle Jones Mar 11 '15 at 19:15

In ksh, bash or zsh:


In any shell, you can remove leading and trailing whitespace and normalize all intermediate whitespace to a single space like this:

set +f
set -- $set_jobs_count
set -f

set +f turns off globbing; if you know that the data contains none of the characters \[?*, you can omit it.

share|improve this answer
interesting answer +1 – munish Mar 1 '12 at 15:02
@BinaryZebra The globbing happens at set -- $set_jobs_count. set_jobs_count=$* is equivalent to set_jobs_count="$@" since $* and $@ are only equivalent when unquoted and the right-hand side of an assignment is parsed the same way as a double-quoted string. – Gilles Jul 26 '15 at 22:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.