problem with I/O script

#!/bin/sh

cd /
while [$1 -ne " "]
do
$2>/Users/a/new
done

this is the problem it out puts

blanker.sh: line 6: [: missing `]'

any help appreciated

You need white space around the brackets...
while [ $1 -ne " " ]

Still didn't work

while [ $1 -ne " " ]
thanks though

But it got rid of the error message you complained about, right? You didn't say it wanted it to work. :slight_smile: In that case...

while [ "$1" -ne " " ]

without the quotes, and if $1 is blank, the shell will just see...
while [ -ne " " ]
which doesn't make sense. (Actually, I missed this at first glance.)

this is weird, it still doesn't work
i'm trying to take input and redirect output into a file, so -ne may not work but since variables are strings, i'm not really sure

here is the sttderr
line 6: [: : integer expression expected

Might be that you need the string comparison operators instead of the integer comparison ones.

while [ -n $1 ]
  do
  $2>/Users/a/new
done

i tried that, but i had to ctrl-c out, which may stop the process, but it still made the .txt file which didn't exist before

You have a logical problem. If option $1 don't exit option $2 became option $1 and in this case option $2 don't exist.

so... would u suggest i put a second loop, or break statement to end it?

i'm trying to make it so that every time a person types a command in, it is is redirected. I could put in an if that needs a string which no one would guess as input. otherwise I don't see a way I can test this effectively or break out of it if i want to without using ctrl-c

The script is stuck in an infinite loop due to the while. Change the while to an if statement if all you want is $2 sent to new.txt file. There is no need to loop for that.

if [ -n $1 ]
then
   $2>/Users/a/new.txt
fi

If $2 is not a UNIX command the "$2>/Users/a/new.txt" line should give you an error.

This script will check for $1 and $2, can you elaborate why you need the 'while' loop?

#!/bin/sh
if [ -z "$1" ] ; then
    echo "Option 1 & 2 are missing, exit now"; exit 1
elif [ -z "$2" ] ; then
    echo "Missing second option, exit now"; exit 1
else
    $2>/Users/a/new
fi

I'm trying to trap a person in this loop so everything they type will not be read

very strange requirements if you ask me. probably a shell script is not what you want.

your right it is weird, but i'd like to try it in .sh

I still don't have the foggiest idea of what you want this script to do. An early attempt at the script (somewhat unintentionally) trapped the user in an infinite loop but it seems you want more. Your only attempt at a description: "I'm trying to trap a person in this loop so everything they type will not be read". Well, ok, no problem...

#! /usr/bin/ksh
while : ; do
     sleep 86400
done

The user is trapped in a loop and nothing they type will be read. Each sleep command will run for a day. So it will loop only once a day resulting in a low load on system. But it is a loop and no input is ever read.

try to put $2 in astring var. then use "echo"

What about if $2 is the password ?

hello,
can some one else gives me a script which allows me to acced to directories which are denied.
thanks.