DenverCoder21
DenverCoder21

Reputation: 887

OSX Bash Shell Script Does Not Run

I'm having a pretty basic shell script that's supposed to run at user login. To achieve this, I followed the guide for Automator from the first answer in this topic: Running script upon login mac

But somehow nothing happens. I also tried to create an application using the script editor with do shell script /blabla/git_credentials.sh which responded with a permission denied.

I don't see whats wrong here.

Oh, here's the script:

echo ""
echo "Setup Git Credentials"
echo "*********************"
echo "Please enter your first name: "
read fname
echo "Please enter your last name: "
read lname
echo "Please enter your mail address: "
read email
git config --global --remove-section user
git config --global user.name "$fname $lname"
git config --global user.email $email
echo "Credentials set." 

Edit: I just found out that the script is being run at login, but it neither opens up a terminal nor waits for my user inputs, I have just an empty Git config after every startup. I 'achieved' this using the script editor with do shell script "$HOME/git_credentials.sh" and saving it as an application, then putting it into the login items.

Upvotes: 1

Views: 4936

Answers (3)

David W.
David W.

Reputation: 107090

The problem is that your Automator's shell script isn't connected to STDIN (i.e. your keyboard). It may run the shell script, but there's no way to pass it input since there's no terminal.

What you need to do is run the Automator action: Ask for Text to get your input.

What I found I had to do was Ask for Text, and then Set the Value of the Variable. I do this for each variable I want as input.

Once I get all of the variables I want, I then run Get the Value of the Variable for each of the variables. This puts the variables into $* for the shell script to pull up.

Now, you can execute the Automator action Run Shell Script with Pass Input as arguments. You can refer to them as $1, $2, etc.

I suggest to try this with a simple script and see if it then works. The problem is that the whole thing may execute in a sub-shell, so once the automator action ends, you lose the values of the variables you've set. I simply don't have enough experience with Automator to know exactly how it works.

Upvotes: 3

czechboy
czechboy

Reputation: 944

Or you are missing #!/bin/bash at the top of your script? Or is this just a part of it?

Upvotes: 0

Andrew Stubbs
Andrew Stubbs

Reputation: 4472

I suspect you script is not currently executable.

Try fixing this by running: chmod +x /blabla/git_credentials.sh

or

chmod 755 /blabla/git_credentials.sh

Upvotes: 1

Related Questions