0

I have been trying to list all the files from the "junk_dir" in a formatted style, listing them off by file name, file size and file type. Although I am not getting these printed off in a formatted way, I am getting them printed out. However, on line 10, I get an error from the command promp tsaying

./junk-skeleton.sh: line 10: [1001=: command not found

The following is my code.

#! /bin/bash 

list_junk()
{
    echo "Junk Directory"

   format="%8s%10s%10s  %-s\n"
   printf "$format" "File" "Size" "Type"
   printf "$format" "----" "----" "----"
   if [$(id -u)= "0"]; then
      dir_list="/home/student/bin/junk_dir/*"
   else
      dir_list=$HOME
   fi

  for file in $dir_list; do
      filename=$(ls -al /home/student/bin/junk_dir)
      filesize=$(wc -c /home/student/bin/junk_dir)
      filetype=$(ls --file-type /home/student/bin/junk_dir)

      printf "$format" $filename $filesize $filetype
   done
}

Also, if anybody has help formatting the printed results, I would appreciate it.

3
  • 2
    Leave a space after [ and before ] Commented Oct 25, 2017 at 16:14
  • @Inian I have tried that, What I got back was ./junk-skeleton.sh: line 10: [: 1001=: unary operator expected Commented Oct 25, 2017 at 16:18
  • Try: if [ $(id -u) = 0 ] Commented Oct 25, 2017 at 16:27

1 Answer 1

1

You need spaces around both the brackets, and between the shell command and the equals sign.

if [ $(id -u) = "0" ]; then echo ROOT; fi
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.