Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Bash script - basic questions for simple script

Programming languages, Coding, Executables, Package Creation, and Scripting.
Message
Author
User avatar
PsySc0rpi0n
Posts: 322
Joined: 2012-10-24 13:54
Location: Bitcoin World
Has thanked: 8 times
Been thanked: 1 time

Re: Bash script - basic questions for simple script

#16 Post by PsySc0rpi0n »

arzgi wrote:
GarryRicketson wrote:

Also, there are better alternatives then "bash" , some people believe that bash stands for "broken again shell" with despicable security record.
That's subjective. Bash is the most popular, and can be used to most scripting needs.

I'd suggest also learning some general programming language later, I would recommend python.

I do 'mixing', call bash scripts from python programs, python programs from bash scripts. Also sed and awk in some programs. Each language has it's own strenghts.
I started with C when I started my (late) graduation! I know the basics of C.
I have also self-taught Python but had to quit due to school. Not enough time for both. I'm a day worker (full-time) and also a full-time parent. So, no much spare time left!

User avatar
PsySc0rpi0n
Posts: 322
Joined: 2012-10-24 13:54
Location: Bitcoin World
Has thanked: 8 times
Been thanked: 1 time

Re: Bash script - evaluate if device is mounted

#17 Post by PsySc0rpi0n »

debiman wrote:
PsySc0rpi0n wrote:Why is this "case esac" returning syntax errors at the first ";;":
you really need to SHOW us!
but in this case i'm fairly sure: functions are not called with () at the end.

Code: Select all

# define function
do_this() {
    this
}
# call it with
do_this
# and not do_this()
I tried the script with the '()?...
Didn't work either.

I think it is interpreted as a terminal command. Returned error is:

Code: Select all

command not found!

User avatar
PsySc0rpi0n
Posts: 322
Joined: 2012-10-24 13:54
Location: Bitcoin World
Has thanked: 8 times
Been thanked: 1 time

Re: Bash script - basic questions for simple script

#18 Post by PsySc0rpi0n »

L_V wrote:@PsySc0rpi0n
I think the priority is to 100% clarify in your mind what you want to achieve before looking for a solution (which is not unique).
You can investigate this for test purpose:

Code: Select all

MOUNT="loop0"
df|awk '{print $1" is mounted on " $6 " !";}'|grep $MOUNT||echo -e "\033[1;31m$MOUNT is not mounted !"
I think you are correct! I previously said I wanted to check if a filesystem was mounted but in fact, it was rather if a file has been successfully attached to loop0 or not. By terminal command this is done using "sudo losteup /dev/loop0 file.ext". What I want was to check if this command was successful or not. For that I ended up using the return value of the command itself.

L_V
Posts: 1477
Joined: 2007-03-19 09:04
Been thanked: 11 times

Re: Bash script - basic questions for simple script

#19 Post by L_V »

You then confirm the importance of first clarifying your goal.
Then, something like this ?

Code: Select all

sudo losetup /dev/loop0 -j file.ext && echo OK || echo failed

User avatar
PsySc0rpi0n
Posts: 322
Joined: 2012-10-24 13:54
Location: Bitcoin World
Has thanked: 8 times
Been thanked: 1 time

Re: Bash script - basic questions for simple script

#20 Post by PsySc0rpi0n »

L_V wrote:You then confirm the importance of first clarifying your goal.
Then, something like this ?

Code: Select all

sudo losetup /dev/loop0 -j file.ext && echo OK || echo failed
I did it like this:

Code: Select all

sudo losetup /dev/loop0 $1
   if [[ $? -ne 0 ]]; then
      echo "Error with $1!" >&2
      exit 1
   fi

HarborView
Posts: 41
Joined: 2014-02-01 02:21
Location: The Space Coast of the USA

Re: Bash script - basic questions for simple script

#21 Post by HarborView »

The problem is not in the case syntax. No need to cite POSIX.

The problem is make_avalaible() and make_unavailable().
Parentheses are not permitted when calling a function. For instance this script produces syntax errors:

Code: Select all

#!/bin/bash
Func1 () {
  echo "Heck, yeah"
}
Func2 () {
  echo "Watch your language.  This is a family forum."
}

echo "======================================="
echo "Let's try a function or 2."
Func1()
Func2()
This script produces the expected output:

Code: Select all

#!/bin/bash
Func1 () {
  echo "Heck, yeah"
}
Func2 () {
  echo "Watch your language.  This is a family forum."
}

echo "======================================="
echo "Let's try a function or 2."
Func1
Func2

Post Reply