0

Getting weird error.

basically this script delete the search in the search for .ipa file in serverpath=/home/gyke69/Desktop/ and it delete the .ipa & .ipa.plist file by choosing in list.

find: paths must precede expression: 'delete'

find: possible unquoted pattern after predicate '-type'?

#!/bin/bash
basedir=/home/gyke69/Desktop/zadmin-update/
serverpath=/home/gyke69/Desktop/

#!/bin/bash
prompt="Please select a file:"
options=( $(find $serverpath -type f -name "*.ipa" -printf "%f\n") )

PS3="$prompt "
select opt in "${options[@]}" "Quit" ; do 
    if (( REPLY == 1 + ${#options[@]} )) ; then
        exit

    elif (( REPLY > 0 && REPLY <= ${#options[@]} )) ; then
        echo  "You picked $opt which is file $REPLY"
        break

    else
        echo "Invalid option. Try another one."
    fi
done    

find $basedir -name $opt -type f -delete
find $basedir -name $opt.ipa.plist -type f delete
James Z
  • 12,209
  • 10
  • 24
  • 44
gyke69
  • 1
  • Which `find` command is producing the error? Also, what's the exact command being executed? Add the command `set -x` at the beginning of the script to get an execution trace and see what's happening as the script runs. More generally, you should double-quote variable references, and not rely on word-splitting to parse the output of `find`. See [BashFAQ #20: "How can I find and safely handle file names containing newlines, spaces or both?"](https://mywiki.wooledge.org/BashFAQ/020), and use [shellcheck.net](https://www.shellcheck.net) to spot missed quotes. – Gordon Davisson Apr 17 '22 at 19:35
  • 1
    See also: [How can I store the "find" command results as an array in Bash](https://stackoverflow.com/q/23356779/3266847) – Benjamin W. Apr 17 '22 at 19:45
  • + basedir=/home/gyke69/Desktop/zadmin-update/ + serverpath=/home/gyke69/Desktop/ + prompt=Please select a file: .././selector: 8: Syntax error: "(" unexpected – gyke69 Apr 17 '22 at 20:40
  • @GordonDavisson that is the error i get after i " set -x " – gyke69 Apr 17 '22 at 20:46
  • @gyke69 `Syntax error: "(" unexpected` looks like an error you'd get from dash, not bash (dash doesn't have arrays, and will give this error when it sees `var=(something)`). How are you running the script? – Gordon Davisson Apr 17 '22 at 21:11
  • @GordonDavisson Hey dear my script was totally correct it just there was a typo in the end of the command delete... it should have been -delete. coding is a disaster sometimes haha – gyke69 Apr 17 '22 at 23:32

1 Answers1

0

Looks like just a typo in last line of code. Before delete you didn't put -

dargin
  • 61
  • 4
  • Thank you so much! this fixed the issue. unfortunately can't give you up vote since it requires more reputation. – gyke69 Apr 17 '22 at 23:30