LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-04-2016, 07:26 AM   #16
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,118

Rep: Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160

Quote:
Originally Posted by iFunction View Post
Ok, I have isolated the problem,

Worked like a charm, ...
Any ideas why this would be?
write them on a seperate line.
Code:
#!/bin/bash

echo "type in two or more seperate words"

read -r

event=$REPLY

event=${event^^}
event=${event// /_}


echo "$event"

HI_ME_WHAT_UP?

-----

sudo mkdosfs -n "$event" /dev/sda1 -s 128 -F 32 -I
Structured programming


Bash Structured Programming
Code:
1. send user information
2. get information
3. error handling
4. act on information

Last edited by BW-userx; 01-04-2016 at 07:47 AM.
 
Old 01-04-2016, 08:16 AM   #17
iFunction
Member
 
Registered: Nov 2015
Posts: 248

Original Poster
Rep: Reputation: Disabled
OK, now I'm really confused, both
Code:
event=${event^^}
and
Code:
event=${event// /_}
work fine in the command line, yet it stops in the script. Well to be fair, I don't know what it is doing, as it shuts down the terminal window as soon as enter is hit. This is very strange.
 
Old 01-04-2016, 08:24 AM   #18
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,118

Rep: Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160
Quote:
Originally Posted by iFunction View Post
OK, now I'm really confused, both

Code:
event=${event^^} 
event=${event// /_}
work fine in the command line, yet it stops in the script. Well to be fair, I don't know what it is doing, as it shuts down the terminal window as soon as enter is hit. This is very strange.
Code:
# sets all chars to CAPs, 
# just incase the user forgets or does not do what is needed,
# this is part of error handing.
# it ensures proper formatting of the data you need to work with.

 event=${event^^}

#and 
#replaces all spaces with an underscore
 event=${event// /_}

{var//search pattern/replace with}
Code:
${var^^} #sets chars to caps
${var,,} #sets chars to lower case
your terminal goes away, closes, is no more every time you run your script?

Code:
  GNU nano 2.2.6                                                                  File: formatusb.sh                                                                                                                                          

#/bin/bash
that is what you had in your script in this post eairer. your first line needs to go away or put it under the crunch bang/bin/bash

which is missing the bang btw, it needs to look like this

Code:
#!/bin/bash
that is the proper format it always goes top line right on the left side border in order for a BASH script to work

Last edited by BW-userx; 01-04-2016 at 09:05 AM.
 
1 members found this post helpful.
Old 01-04-2016, 12:03 PM   #19
iFunction
Member
 
Registered: Nov 2015
Posts: 248

Original Poster
Rep: Reputation: Disabled
Right then, I think I've found the problem, it all works perfectly but not from the desktop shortcut. Which is this:
Code:
[Desktop Entry]
Name=Format USB
Comment=Script to format 64Gb usb drive to FAT32
Icon=/usr/share/my_icons/formatusb.png
Exec=lxterminal -e /home/pi/Documents/bash_scripts/format.sh
Type=Application
Terminal=False
I have tried setting Terminal to True, but it still closes down as soon as you press enter to input the name. I have also tried to use zenity to ask the question to see if that would work, but now it just closes the terminal window straight away.

What am I missing here, having this run from a simple desktop icon is essential for this program.

Kind regards
iFunc
 
Old 01-04-2016, 12:14 PM   #20
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,118

Rep: Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160
Quote:
Originally Posted by iFunction View Post
Right then, I think I've found the problem, it all works perfectly but not from the desktop shortcut. Which is this:
Code:
[Desktop Entry]
Name=Format USB
Comment=Script to format 64Gb usb drive to FAT32
Icon=/usr/share/my_icons/formatusb.png
Exec=lxterminal -e /home/pi/Documents/bash_scripts/format.sh
Type=Application
Terminal=False
I have tried setting Terminal to True, but it still closes down as soon as you press enter to input the name. I have also tried to use zenity to ask the question to see if that would work, but now it just closes the terminal window straight away.

What am I missing here, having this run from a simple desktop icon is essential for this program.

Kind regards
iFunc
it might be because it does not take that long to run it period, try it striaght off the command line and see how long it takes your PC, with mine it was like a millisecond to complete the action, because it is set to run that script after it is complete it no longers needs to be open (the Term). In other words the way you have it set it is doing what it is suppose to be doing.

try removing the
Code:
 -e
then see what it does.

Last edited by BW-userx; 01-04-2016 at 12:29 PM.
 
Old 01-04-2016, 05:57 PM   #21
iFunction
Member
 
Registered: Nov 2015
Posts: 248

Original Poster
Rep: Reputation: Disabled
It's just really strange that it runs perfectly without those two lines correcting the input, I just don't get it, how can two lines of code conditioning the input string suddenly get the script to shutdown when using a desktop icon. Yet either, run program from command line and it works fine, or remove the two lines and it runs perfectly from the desktop icon. Just does not have any logic behind it that I can get my head around it.

It's not like I am asking the computer to make a cup of tea with milk, I just want to format a usb stick from the double click of a button, there must be a way to do this!
 
Old 01-04-2016, 06:32 PM   #22
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,118

Rep: Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160
Quote:
Originally Posted by iFunction View Post
It's just really strange that it runs perfectly without those two lines correcting the input, I just don't get it, how can two lines of code conditioning the input string suddenly get the script to shutdown when using a desktop icon. Yet either, run program from command line and it works fine, or remove the two lines and it runs perfectly from the desktop icon. Just does not have any logic behind it that I can get my head around it.

It's not like I am asking the computer to make a cup of tea with milk, I just want to format a usb stick from the double click of a button, there must be a way to do this!
if it is the same script I do not know, I do not have shortcuts on DT I run i3 WM I use my Keyboard shortcuts so I cannot run it on my system to see what's up. pray someone esle steps in and can help you in your delima

though you could just take a good look at it or post it

Last edited by BW-userx; 01-04-2016 at 06:36 PM.
 
Old 01-05-2016, 12:52 AM   #23
iFunction
Member
 
Registered: Nov 2015
Posts: 248

Original Poster
Rep: Reputation: Disabled
Thanks very much for all your help BW, you have cleared up lots for me, ultimately, I am just going to have to post instruction and hope they follow it.
 
Old 01-05-2016, 04:32 AM   #24
iFunction
Member
 
Registered: Nov 2015
Posts: 248

Original Poster
Rep: Reputation: Disabled
Solved, This is just an update as this has now been solved the issue was due to lxterminal using /bin/sh instead of /bin/bash. ${xxx^^} is a bash thing and doesn't work under the sh shell, so the following line in the desktop shortcut was modified to tell the Exec line to use bash as follows:
Code:
Exec=lxterminal -e /bin/bash /hom/pi/Documents/bash_scripts/formatusb.sh
Thanks for all input on this thread, I have learnt a lot.

iFunk
 
Old 01-05-2016, 05:44 AM   #25
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,118

Rep: Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160Reputation: 2160
Quote:
Originally Posted by iFunction View Post
Solved, This is just an update as this has now been solved the issue was due to lxterminal using /bin/sh instead of /bin/bash. ${xxx^^} is a bash thing and doesn't work under the sh shell, so the following line in the desktop shortcut was modified to tell the Exec line to use bash as follows:
Code:
Exec=lxterminal -e /bin/bash /hom/pi/Documents/bash_scripts/formatusb.sh
Thanks for all input on this thread, I have learnt a lot.

iFunk
Good at least you figured it out, another alternative would be to change lxterminal to run /bin/bash instead
Code:
chsh -s /bin/bash

Last edited by BW-userx; 01-05-2016 at 06:58 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
replace 8 times successive spaces by | sumeet inani Linux - Newbie 12 10-06-2011 06:31 PM
Is there a script for changes spaces to underscores? DJOtaku Linux - General 4 02-04-2008 09:28 PM
script to replace spaces with - lleb Linux - Newbie 16 01-04-2008 04:15 PM
Cannot replace spaces w/ underscores clem_c_rock Linux - Newbie 7 09-27-2007 01:17 PM
How to replace spaces in filenames with underscores rosslaird Linux - Software 4 02-22-2005 01:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration