0

I'm trying to write a program that will get an object from github, without cloning the entire repo. The last line does not work, giving me a Syntax error: "(" unexpected. It is supposed to remove all files / directories except for that.

#!/bin/sh
object=$2 #sets item not to remove as second argument
address=$1 #sets github address (github.com/user/repo)
git clone $1 #clones it
location="${address##*/}" #gets part after last backslash
cd $location #cd's into it

#Syntax error: "(" unexpected
rm -rf !("$object") 
2
  • What are you expecting that line to do? Perhaps you're trying to use bash's extglobs, in which case you'll need to use bash not sh and enable them with shopt -s extglob Commented Sep 17, 2016 at 0:33
  • changed the text Commented Sep 17, 2016 at 0:36

1 Answer 1

0

The extglob syntax for bash is not enabled by default, and that's what will give you the !(...) syntax. You'll have to turn it on if you want, by first changing your shebang to use bash

#! /bin/bash

then by turning on extglob by adding

shopt -s extglob

somewhere before that line

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.