Swapped Mint14 for Mint16, issue running shell script

Forum rules
Before you post please read this

Swapped Mint14 for Mint16, issue running shell script

Postby dwsa on Mon Jun 23, 2014 3:32 pm

Hello, just this morning I installed Linux Mint 16 Cinnamon 32bit. I had been using mint 14 in the past and finally decided to update. I re-installed linux to my pc using the image found on this website. At which point, I noticed something. While I began to remake alot of my old scripts, I noticed one that now resulted in an error. The script I'm trying to run:

Code: Select all
#!/bin/bash
# init
echo & echo "(Website):" && read input
output=$(ping -c 1 "$input" 2>/dev/null)
if [ $? -eq 0 ]; then
     ip=$(printf '%s' "$output" | gawk -F'[()]' '/PING/{print $2}'  2>/dev/null)
     clear
     echo
     echo "$ip";
     echo -n $ip | xclip -selection c
     echo
     echo IP copied to clipboard.
     sleep 2
     exit
else
     clear
     echo "Host not found";
     sleep 1
     exit
fi 


When I installed Mint this morning, I made sure to update everything through the update manager. (levels 1 & 2)
I have not really changed the script, when I was using Linux Mint 14 (cinnamon) this very script worked without issue.

But now, when I open a terminal and type:
Code: Select all
sh ~/Desktop/shell.sh

it returns:
Code: Select all
: not found/Desktop/shell.sh: 3: /home/user/Desktop/shell.sh: 
(Website): 

The script says it can not be found, but continues. So, I type in "google.com" and press enter.
It returns:
Code: Select all
: bad variable name/shell.sh: 4: read:
: not found/Desktop/shell.sh: 5: /home/user/Desktop/shell.sh:
/home/user/Desktop/shell.sh: 24: /home/user/Desktop/shell.sh: Syntax error: word unexpected


Am I doing something wrong? Have I installed something improperly? Is this something with the shell itself?
I don't really understand where this error is coming from. Help is always appreciated.

Thanks in advance
dwsa
Level 1
Level 1
 
Posts: 7
Joined: Mon Jun 23, 2014 2:51 pm

Linux Mint is funded by ads and donations.
 

Re: Swapped Mint14 for Mint16, issue running shell script

Postby xenopeek on Mon Jun 23, 2014 3:39 pm

Welcome to the Linux Mint forums :) Moved your topic here; the place to ask about shell scripts.

I'd urge you to do one more swap, namely to Linux Mint 17. Linux Mint 16 becomes obsolete shortly as it reaches end of support in July: http://www.linuxmint.com/download_all.php

As for the error you got, line 3 can't be correct--right? Shouldn't that be && instead of &
User avatar
xenopeek
Level 21
Level 21
 
Posts: 14994
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Swapped Mint14 for Mint16, issue running shell script

Postby dwsa on Mon Jun 23, 2014 3:48 pm

xenopeek wrote:Welcome to the Linux Mint forums :) Moved your topic here; the place to ask about shell scripts.

I'd urge you to do one more swap, namely to Linux Mint 17. Linux Mint 16 becomes obsolete shortly as it reaches end of support in July: http://www.linuxmint.com/download_all.php

As for the error you got, line 3 can't be correct--right? Shouldn't that be && instead of &


Hello, thanks for the welcome. I actually think I may have double posted this topic (sorry if I did).

The use of "&" is just a habbit I picked up with windows and serves no real purpose. I meant to delete that. (it's not in the script anymore)

I will take a look at Mint 17, thanks for the heads up!
dwsa
Level 1
Level 1
 
Posts: 7
Joined: Mon Jun 23, 2014 2:51 pm

Re: Swapped Mint14 for Mint16, issue running shell script

Postby xenopeek on Mon Jun 23, 2014 4:03 pm

I'd write the
Code: Select all
echo & echo "(Website):" && read input

as
Code: Select all
echo
echo -n "(Website):"
read input

instead. -n suppresses the newline after echo.
User avatar
xenopeek
Level 21
Level 21
 
Posts: 14994
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Swapped Mint14 for Mint16, issue running shell script

Postby dwsa on Mon Jun 23, 2014 4:45 pm

Even with the changes, it still fails with the same error
Code: Select all
user@system ~ $ sh ~/Desktop/shell.sh
: not found/Desktop/shell.sh: 3: /home/user/Desktop/shell.sh:
: not found/Desktop/shell.sh: 4: /home/user/Desktop/shell.sh: echo
(Website):

again, I type "google.com" and press enter:
Code: Select all
: bad variable name/shell.sh: 6: read:
: not found/Desktop/shell.sh: 7: /home/user/Desktop/shell.sh:
/home/user/Desktop/shell.sh: 26: /home/user/Desktop/shell.sh: Syntax error: word unexpected

I'm not sure why it keeps failing
dwsa
Level 1
Level 1
 
Posts: 7
Joined: Mon Jun 23, 2014 2:51 pm

Re: Swapped Mint14 for Mint16, issue running shell script

Postby WharfRat on Mon Jun 23, 2014 8:52 pm

I tried running your original script in mint petra x86_64 and had no problems.

I unset $BASH in the environment, started it with ./shell.sh, bash -c ~/Desktop/shell.sh, sh ~/Desktop/shell.sh and it worked. So the errors you're getting is very odd.

The only suggestion I can make is try reinstalling bash.
Image
User avatar
WharfRat
Level 12
Level 12
 
Posts: 4273
Joined: Thu Apr 07, 2011 8:15 pm

Re: Swapped Mint14 for Mint16, issue running shell script

Postby dwsa on Mon Jun 23, 2014 10:34 pm

WharfRat wrote:I tried running your original script in mint petra x86_64 and had no problems.

I unset $BASH in the environment, started it with ./shell.sh, bash -c ~/Desktop/shell.sh, sh ~/Desktop/shell.sh and it worked. So the errors you're getting is very odd.

The only suggestion I can make is try reinstalling bash.

By bash, you mean the whole shell? How do I re-install the shell?
ps the output of "echo $BASH_VERSION" is:
Code: Select all
4.2.45(1)-release
dwsa
Level 1
Level 1
 
Posts: 7
Joined: Mon Jun 23, 2014 2:51 pm

Re: Swapped Mint14 for Mint16, issue running shell script

Postby WharfRat on Mon Jun 23, 2014 11:48 pm

I'm at the same version.

Code: Select all
wharfrat@mint ~ $ bash --version
GNU bash, version 4.2.45(1)-release (x86_64-pc-linux-gnu)


bash is a package that can be installed so just reinstall it.

Code: Select all
sudo apt-get install --reinstall bash


Is there any difference if you

sudo bash -c ~/Desktop/shell.sh :?:

Also are you logged in as a guest user or is your user name user :?:
Image
User avatar
WharfRat
Level 12
Level 12
 
Posts: 4273
Joined: Thu Apr 07, 2011 8:15 pm

Re: Swapped Mint14 for Mint16, issue running shell script

Postby dwsa on Mon Jun 23, 2014 11:58 pm

WharfRat wrote:I'm at the same version.

Code: Select all
wharfrat@mint ~ $ bash --version
GNU bash, version 4.2.45(1)-release (x86_64-pc-linux-gnu)


bash is a package that can be installed so just reinstall it.

Code: Select all
sudo apt-get install --reinstall bash


Is there any difference if you

sudo bash -c ~/Desktop/shell.sh :?:

Also are you logged in as a guest user or is your user name user :?:

The user account is actually called user, even when I run with root the same error occurs.
I've even re-installed the shell itself, seems to have made no difference.

Does this mean I have a problem somewhere else? -Thanks in advance.
dwsa
Level 1
Level 1
 
Posts: 7
Joined: Mon Jun 23, 2014 2:51 pm

Re: Swapped Mint14 for Mint16, issue running shell script

Postby WharfRat on Tue Jun 24, 2014 12:53 am

I've never encountered an error like : not found/Desktop/shell.sh: 3: /home/user/Desktop/shell.sh:.

I see it starts complaining as soon as you start the script. Does any other script exhibit that problem.

I doubt your init scripts would complete successfully if it was happening with every script :?

Will this run without error :?:

Code: Select all
#!/bin/bash
#
echo -n "Memory " ;grep MemTotal: /proc/meminfo | awk '{printf( "%\047d\n", $2)}'
echo "Boot directory contents: " && ls -lh /boot | egrep 'kernel|initram|initrd|vmlinuz'
echo -n $(lscpu | grep MHz) ; [[ -e /usr/bin/cpufreq-set ]] && echo " CPU might be governed by cpufrequtils" || echo
[[ -e /usr/bin/cpufreq-set ]] && cpufreq-info -o || echo "Not governed by cpufrequtils"
echo -n "Sound card(s):"; echo -n $(grep -i codec /proc/asound/card*/codec\#* | cut -d: -f3);echo
exit 0
Image
User avatar
WharfRat
Level 12
Level 12
 
Posts: 4273
Joined: Thu Apr 07, 2011 8:15 pm

Re: Swapped Mint14 for Mint16, issue running shell script

Postby dwsa on Tue Jun 24, 2014 12:59 am

WharfRat wrote:I've never encountered an error like : not found/Desktop/shell.sh: 3: /home/user/Desktop/shell.sh:.

I see it starts complaining as soon as you start the script. Does any other script exhibit that problem.

I doubt your init scripts would complete successfully if it was happening with every script :?

Will this run without error :?:

Code: Select all
#!/bin/bash
#
echo -n "Memory " ;grep MemTotal: /proc/meminfo | awk '{printf( "%\047d\n", $2)}'
echo "Boot directory contents: " && ls -lh /boot | egrep 'kernel|initram|initrd|vmlinuz'
echo -n $(lscpu | grep MHz) ; [[ -e /usr/bin/cpufreq-set ]] && echo " CPU might be governed by cpufrequtils" || echo
[[ -e /usr/bin/cpufreq-set ]] && cpufreq-info -o || echo "Not governed by cpufrequtils"
echo -n "Sound card(s):"; echo -n $(grep -i codec /proc/asound/card*/codec\#* | cut -d: -f3);echo
exit 0


As of now, this is the only script resulting in an error that I could not explain.
The output of above is

Code: Select all
user@system ~ $ #!/bin/bash
user@system ~ $ #
user@system ~ $ echo -n "Memory " ;grep MemTotal: /proc/meminfo | awk '{printf( "%\047d\n", $2)}'
Memory 3,721,512
user@system ~ $ echo "Boot directory contents: " && ls -lh /boot | egrep 'kernel|initram|initrd|vmlinuz'
Boot directory contents:
-rw-r--r-- 1 root root  25M Jun 23 10:11 initrd.img-3.11.0-12-generic
-rw-r--r-- 1 root root 5.4M Nov 26  2013 vmlinuz-3.11.0-12-generic
user@system ~ $ echo -n $(lscpu | grep MHz) ; [[ -e /usr/bin/cpufreq-set ]] && echo " CPU might be governed by cpufrequtils" || echo
CPU MHz: 1320.000
user@system ~ $ [[ -e /usr/bin/cpufreq-set ]] && cpufreq-info -o || echo "Not governed by cpufrequtils"
Not governed by cpufrequtils
user@system ~ $ echo -n "Sound card(s):"; echo -n $(grep -i codec /proc/asound/card*/codec\#* | cut -d: -f3);echo
Sound card(s):
Last edited by dwsa on Tue Jun 24, 2014 1:27 am, edited 1 time in total.
dwsa
Level 1
Level 1
 
Posts: 7
Joined: Mon Jun 23, 2014 2:51 pm

Re: Swapped Mint14 for Mint16, issue running shell script

Postby xenopeek on Tue Jun 24, 2014 1:05 am

He meant putting that in a file, making it executable, and running it. Not pasting it on the terminal :|
User avatar
xenopeek
Level 21
Level 21
 
Posts: 14994
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Swapped Mint14 for Mint16, issue running shell script

Postby dwsa on Tue Jun 24, 2014 1:10 am

xenopeek wrote:He meant putting that in a file, making it executable, and running it. Not pasting it on the terminal :|

thats exactly what I did. .?

I took the code he gave me, put it in a shell.sh, and it returned the errors above. What did I do wrong? :| Now I'm confused..
dwsa
Level 1
Level 1
 
Posts: 7
Joined: Mon Jun 23, 2014 2:51 pm

Re: Swapped Mint14 for Mint16, issue running shell script

Postby WharfRat on Tue Jun 24, 2014 8:55 am

Did you save what I gave you to a filename shell.sh :?:

Can you cat and ls -lh the file you created :?:
Image
User avatar
WharfRat
Level 12
Level 12
 
Posts: 4273
Joined: Thu Apr 07, 2011 8:15 pm

Linux Mint is funded by ads and donations.
 

Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 3 guests