-2

Hi I am trying to make a shell script that can create a directory (/mnt/drive) and mount a exFAT drive in that directory on my raspberry pi 2. The problem I am having is that when I try to run the file that I made it does not run. By the way, I did run chmod u+x before I ran the file.

Here is the file that I made

#!/bin/bash

update() {

    install_log "Updating and Upgrading"
    sudo apt-get update;
    check_exit_status

    sudo apt-get upgrade -y;
    check_exit_status
}
install-packages() {

    install_log "installing required packages"
    sudo apt-get install exfat-fuse exfat-utils
    check_exit_status
}
create-directory() {

  install_log "creating mount directory"
  sudo mkdir /mnt/drive
  check_exit_status
}
mount-drive() {

   install_log "mounting drive"
   sudo mount /dev/sda2 /mnt/drive
   check_exit_status
}
finished() {

  echo finished. press control q to exit
  check_exit_status
}
  • 2
    The Pi is irrelevant to the question which is therefore off-topic. By the way all the script does is define a series of functions. None are actually called. – joan Nov 8 '19 at 22:29
  • Sorry for not adding that I was doing this on my raspberry pi 2. Just edited it. – Jesus Coder Nov 8 '19 at 23:47
0

The problem I am having is that when I try to run the file that I made it does not run.

The "script" you have is just a set of functions. Consider:

#!/bin/bash

var1=3
foo=okay
more=$foo then

I can set this executable and execute it, but it does nothing, so nothing will happen.

If you want the script to actually run one of the functions it defines, you'll have to call it in the script, eg.

create_directory

Alternately, you could source thescript.sh and then call the functions from the command line.

  • Thank you for answering my question. After removing the functions that were around the terminal commands and ran the file, it ran smoothly without errors. – Jesus Coder Nov 8 '19 at 23:17
  • 1
    I do not understand what policy do you follow to be the question not off-topic. – Ingo Nov 9 '19 at 7:13
  • @Ingo I'm inconsistent, if that's what you mean ;) By the same token, I generally don't close questions that have a decent answer where I might have closed it if it didn't. Long ago there was a lot of discussion here about our "grey areas" where we overlap w/ U&L, SO, and EE. We knew that if we were very strict about that, there wouldn't be enough viable "non gray" left. At the same time, we did not want to allow it all as a matter of policy because in the end that would not benefit anyone much (we can't provide what those bigger sites do). – goldilocks Nov 9 '19 at 13:59
  • So, I know I do seem inconsistent sometimes and would not deny it. I generally do not think I am excessively unfair, however. If I've closed a question and you'd really like to answer it, just ping me or another mod in chat. I can't promise we say yes to everyone all the time of course. And maybe I will delete this comment later, lol... – goldilocks Nov 9 '19 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.