11 Replies - 1570 Views - Last Post: 19 September 2013 - 02:45 PM

#1 CodeCapition1   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 57
  • Joined: 23-September 10

new to linux having bash and terminal issues i think

Posted 19 September 2013 - 09:13 AM

first off i am a total linux newbie but here goes. i am trying to write a bash script to open the terminal and change to a specific DIR. not to difficult i think just around 3 lines in the file. my issue is not with the script itsself not working i dont think, it seams to be some sort of file or extension association issue. when i save my file as filename.sh and double click on it it does open the terminal but it appears to be running a different script, one written to open another program. it does this with every .sh or bash file throughout the whole machine, i have found a half dozen and tried to double click them and it opens the same script as before to start the same program. this is my work machine so it was set up for me along with the program and script in question which for that it works wonderfully. i just can not for the life of me figure out why when i double click my or any other script it runs the CNUT startup tool script, it does not matter where or what script i try to double click it always opens the one. any ideas on why this would be happening or where to look to try to figure out what to do? i have done some searching but have found mainly resources on creating the script or setting up file associations. not much on why when one script is clicked another opens and runs.

Is This A Good Question/Topic? 0
  • +

Replies To: new to linux having bash and terminal issues i think

#2 no2pencil   User is online

  • Professor Snuggly Pants
  • member icon

Reputation: 6824
  • View blog
  • Posts: 31,471
  • Joined: 10-May 07

Re: new to linux having bash and terminal issues i think

Posted 19 September 2013 - 11:06 AM

What distribution are you running? You should open the terminal & run the script. If your script doesn't hold the console window open, it will close when it's finished. & if all that it's doing is changing to a directory, it will be REALLY REALLY fast.
Was This Post Helpful? 0
  • +
  • -

#3 CodeCapition1   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 57
  • Joined: 23-September 10

Re: new to linux having bash and terminal issues i think

Posted 19 September 2013 - 11:40 AM

ok im runnig fedora 18 i think or some version of fedora. but anyway the script will execute if i force it from the terminal but if i double click on the file in a folder called scripts on my desktop it "magically" opens and runs a different script completely, one that i have given no reference to. when this machine was set up a program called Network updater tool was installed and if i double click the icon for that program on my desktop it opens a terminal window that says" starting Network Updater tool... press enter when finished with the tool" that window will stay open and then the Network updater will open and run just fine. i then close down that program and open my scripts folder on my desktop and double click on the script to change directory and here it comes "magically" the Network updater tool script runs again. it seams like somehow the terminal has been linked with this script and when i try to open any script it reverts and opens the network updater tool script???? im most certainly stumped on this one.

no2pencil: i have noticed you reply to a lot of my posts when i ask for help, at least i see your name a lot in replies to my posts. for your help my appreciation is extended to you good sir.
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil   User is online

  • Professor Snuggly Pants
  • member icon

Reputation: 6824
  • View blog
  • Posts: 31,471
  • Joined: 10-May 07

Re: new to linux having bash and terminal issues i think

Posted 19 September 2013 - 11:46 AM

Your description, though very detailed, makes an assumption. It's difficult, if not impossible, to troubleshoot on assumptions.

Is it possible to look through your network uploader script & custom script & verify that one does or does not reference one another.

& no problem replying. I try to help with what I can, when I can.
Was This Post Helpful? 0
  • +
  • -

#5 CodeCapition1   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 57
  • Joined: 23-September 10

Re: new to linux having bash and terminal issues i think

Posted 19 September 2013 - 12:25 PM

yeah i do make a guess at what i think is the problem is, and your right assumptions are hard to troubleshoot. but anyway here is the the code from both files:


this is the network updater script:
#!/bin/bash
clear
tput cup 5 0
echo "Launching Crappy Network Update Tool (CNUT)..."
cd /usr/local/motorola/networkupdater/
sudo ./CNUTLauncher.sh
echo
echo -n "Press enter when you are done using CNUT..."
read userin




and here is my change dir script:
#!/bin/bash

# Script Configure Canopy; launch terminal and change to working DIR with command ready to execute

working_dir=~/bin/configcanopy

cd $working_dir


read userin



the only other thing i think i could refference would be my file association config file if that would help
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil   User is online

  • Professor Snuggly Pants
  • member icon

Reputation: 6824
  • View blog
  • Posts: 31,471
  • Joined: 10-May 07

Re: new to linux having bash and terminal issues i think

Posted 19 September 2013 - 12:28 PM

I would suggest the following :

#!/bin/bash

# Script Configure Canopy; launch terminal and change to working DIR with command ready to execute

working_dir="~/bin/configcanopy"

cd $working_dir 2>/dev/null
if [ $? -ne 0 ]; then
  echo There was an issue trying to enter ${working_dir}
fi

echo I am currently in `pwd`

read userin



Alternatively :

#!/bin/bash

# Script Configure Canopy; launch terminal and change to working DIR with command ready to execute

working_dir="~/bin/configcanopy"

if [ -d ${working_dir} ]; then
  cd $working_dir
else
  echo ${working_dir} does not exist!
fi

echo I am currently in `pwd`

read userin


Was This Post Helpful? 0
  • +
  • -

#7 CodeCapition1   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 57
  • Joined: 23-September 10

Re: new to linux having bash and terminal issues i think

Posted 19 September 2013 - 12:46 PM

thoes scripts have some nice added usability thanks. but the issue im having is not with getting the script to work or work properly or to be the most efficent. the issue is no matter what script i write
it could be as simple as echo a message and wait for a key press as in:
!#/bin/bash
echo script runs fine
read userin



even that script refuses to run if i double click on the file icon in my scripts folder, but if i open a CLI and cd to the DIR that script is in and force execution from the terminal with
./start_terminal.sh


it will run just fine and does exactly as its supposed to. but the double click will still invoke the CNUT launcher script even with both of your suggested scripts in place of mine????
Was This Post Helpful? 0
  • +
  • -

#8 no2pencil   User is online

  • Professor Snuggly Pants
  • member icon

Reputation: 6824
  • View blog
  • Posts: 31,471
  • Joined: 10-May 07

Re: new to linux having bash and terminal issues i think

Posted 19 September 2013 - 12:48 PM

Did you change the execute value of the files? 777 or whatever... do an ls -l & provide what the line reports.
Was This Post Helpful? 0
  • +
  • -

#9 CodeCapition1   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 57
  • Joined: 23-September 10

Re: new to linux having bash and terminal issues i think

Posted 19 September 2013 - 01:28 PM

yeah that was one of the first things i tried i usually use 755 as the permissions but i went ahead and tried 777 like you suggested but still no luck here is the output from the terminal:
[email protected] script2$ ls -l
total 4
-rwxrwxrwx. 1 tjack tjack 176 Sep 19 15:09 start_terminal.sh
[email protected] script2$ ./start_terminal.sh 
script is working

[email protected] script2$ 



i did change the contents of the script file to the simple echo and wait from my last post. it worked just fine from the terminal but i double clicked the gui icon and a terminal window popped up with this inside:

Launching Crappy Network Update Tool (CNUT)...
./CNUTLauncher.sh: line 13: type: htmlview: not found

Press enter when you are done using CNUT...




that is what i get everytime i double click a shell script file anywhere on my machine be it the desktop, root of the hard drive, inside the bin DIR, or in my personal user home DIR.
Was This Post Helpful? 0
  • +
  • -

#10 no2pencil   User is online

  • Professor Snuggly Pants
  • member icon

Reputation: 6824
  • View blog
  • Posts: 31,471
  • Joined: 10-May 07

Re: new to linux having bash and terminal issues i think

Posted 19 September 2013 - 01:40 PM

Try this :

#!/bin/bash
clear
tput cup 5 0
script="CNUTLauncher.sh"
echo "Launching Crappy Network Update Tool (CNUT)..."
cd /usr/local/motorola/networkupdater/
if [ ! -f ${script} ]; then
  location=`which ${script}`
  if [ $? -eq 0 ]; then
     cd ${location}
  else
     echo Looking deeper, this may take a while...
     location=`find . -name ${script} 2>/dev/null`
     if [ $? -eq 0 ];
       echo Couldn't automagically find ${script}
       exit 1
     else
       ## Real ify on this part...
       echo ${location}
     fi
   fi
fi     
echo -n "Press enter when you are done using CNUT..."   
sudo ./${script}
read userin



It's probably not so deep that we need the find command, but I'm just going for broke.
Was This Post Helpful? 1
  • +
  • -

#11 CodeCapition1   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 57
  • Joined: 23-September 10

Re: new to linux having bash and terminal issues i think

Posted 19 September 2013 - 02:02 PM

ok first i forgot to remove the line numbers and got this error
[email protected] script2$ ./start_terminal.sh
./start_terminal.sh: line 19: 02: command not found
./start_terminal.sh: line 20: 03: command not found
./start_terminal.sh: line 21: 04: command not found
./start_terminal.sh: line 22: 05: command not found
./start_terminal.sh: line 23: 06: command not found
./start_terminal.sh: line 24: syntax error near unexpected token `then'
./start_terminal.sh: line 24: `07	if [ ! -f ${script} ]; then'
[email protected] script2$ 


then once i fixed that i got this as output in the terminal window
Launching Crappy Network Update Tool (CNUT)...
./start_terminal.sh: line 16: syntax error near unexpected token `else'
./start_terminal.sh: line 16: `	     else'
[email protected] script2$ 



still no luck and if i save it as my file and try to double click start_terminal.sh again the same thing happens the CNUTlauncher.sh script is called not the start_terminal.sh script.

ps i love ther automagically i took me a few reads to find it

anyway i about done for the day and i appreciate your help but im going to give up for tonight and hope our sys admin is feeling helpful tomorrow maybe with some sleep and some more fresh eyes we can get it working

This post has been edited by CodeCapition1: 19 September 2013 - 02:07 PM

Was This Post Helpful? 0
  • +
  • -

#12 no2pencil   User is online

  • Professor Snuggly Pants
  • member icon

Reputation: 6824
  • View blog
  • Posts: 31,471
  • Joined: 10-May 07

Re: new to linux having bash and terminal issues i think

Posted 19 September 2013 - 02:45 PM

Line 14 should have an 'then'

if []; then
Sorry.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1