In shell scripting, a shell such as bash runs a file containing a list of commands (a script). The script is effectively a program and the shell is its interpreter.

learn more… | top users | synonyms

11
votes
5answers
2k views

What does >> or double Angle brackets mean? [duplicate]

It seems like such a simple questions but I cant find any resource regarding it In C/C++ , it means to store the read in a value from command prompt and store it inside a variable , How about in ...
11
votes
5answers
2k views

Run a command with the argument from the last command

When running commands, sometimes maybe you need to run a command with the argument from the last command. How can you do this? Of course, excepting the use of the arrow keys and Del keys: ...
11
votes
4answers
4k views

How do I limit Dropbox's activity on the hard disk?

On startup, Dropbox runs files indexing, which brings the system pretty much to a stand still for three minutes. Is there a way to restrict Dropbox from accessing the hard disk, or decrease the ...
11
votes
1answer
439 views

Bash comparison and expression operators

I'm new to bash programming. I've read two good, long guides, but they made a mess in my head about operators and keywords. Which are more commonly and widely used? I don't know when to use which ...
9
votes
6answers
709 views

How to get the URL from a file using a shell script

I have a file which consists of a URL. I'm trying to get the URL from that file using a shell script. In the file, the URL is like this: ('URL', 'http://url.com'); I tried to use the following: ...
9
votes
6answers
15k views

Not able to execute a .sh file: /bin/bash^M: bad interpreter

I wanted to execute a shell script: -rwxr-x--x 1 root root 17234 Jun 6 18:31 create_mgw_3shelf_6xIPNI1P.sh I tried to do a standard procedure, but I am got this error: ...
8
votes
2answers
11k views

Why doesn't rc.local run all my commands, and what can I do about it?

I have the following rc.local script: #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # ...
7
votes
1answer
906 views

How do I add a PPA in a shell script without user input?

Basically, I want to run add-apt-repository ppa:(whatever) without the "press Enter to continue" prompt. How would I do this? Essentially, I want to deploy adding a repository in a shell script ...
6
votes
3answers
6k views

How to run a script during boot as root

I had a script that automatically enables my wifi without using networkmanager, but I don't know how to run the script as root while the system is booting. How do I make the script run automatically ...
6
votes
2answers
3k views

Using a variable inside `sed` command

I am using this command to copy certain line from one file to another.Its working fine.No issue with it. sed -f <(sed -e '1,10d; 12,$d; x; s/.*/10a\/;p; x' ../log/file2.txt ) ../log/file4.txt > ...
5
votes
1answer
102 views

How to get select statement choices into If statements?

I'm very new to programming on Ubuntu. And I'm trying to do a simple bash script. I have a select menu working but I want the choices made in that to go into a number of if statements, corresponding ...
5
votes
1answer
1k views

Reliably check if a package is installed or not

I have a simple requirement. I want to define several variables that will correspond to any number of given packages I want to install via a shell script. Sample code below: MISC="shutter pidgin" ...
5
votes
4answers
220 views

Pulling multiple alternatives from a variable in a case condition

I'd like to use variable as condition in case statement. Something similar to: #!/bin/sh ALLOWED_SERVICES=tomcat6|james; case $1 in $ALLOWED_SERVICES ) service $1 restart ;; * ) ...
5
votes
1answer
2k views

Open Terminal with multiple tabs and execute application

I am new to linux shell scripting. I want to write a shell script which will open terminal with multiple tabs; it should run rtsp client app in each tab. For this, I have gone through question here ...
5
votes
1answer
491 views

shell script to conditionally add apt repository

I want to write a shell script that will add an apt repository. I know that I can do it using sudo add-apt-repository -y <repo>. My question is can I do it only if the repository was not ...
5
votes
3answers
257 views

Convey some message to all users

Is it possible to write a shell script that enables any user (may not be root) to set a message(e.g. "Download on progress do not turn off" etc.) which will be conveyed like pop-up message (zenity or ...
4
votes
4answers
218 views

CDIR= $(pwd) gives “Permission denied”

I have a very simple shell script, called deploy.sh #!/bin/sh CDIR= $(pwd) echo Hello World! Unfortunately, running it gives the following error: bird@bird-laptop:~/foo$ sh deploy.sh deploy.sh: ...
4
votes
3answers
170 views

How can I process multi-line records with awk in a bash script?

example.txt is below Restaurant: McDonalds City: Miami State: Florida Address: 123 Biscayne Blvd Phone: 911 Restaurant: 5 guys City: Atlanta State: Georgia Address: 123 Peachtree Rd Phone: 911 ...
4
votes
2answers
187 views

How do I iterate the arguments in a bash script?

Is there any method to iterate the passed arguments in a bash script? This answer from my question shows me how to use each argument, but I want to iterate them because the number of arguments is ...
4
votes
2answers
1k views

How to uppercase first letter of the first word in each sentence using shell script?

I am trying to capitalize each first letter of the first word in each sentence from a txt file called input.txt and I want this input file to be a argument of the shell script ./script.sh input.txt ...
4
votes
2answers
127 views

Add “not” to if statement in shell script

I have the following script that should exist if the user does not exist. #check if user currently exists on system if id $User > /dev/null 2>&1 then #user exists no need to exit ...
4
votes
1answer
571 views

Can I start a program from the terminal and make it launch visually in the background?

If I open a program, like Firefox, from the terminal then that program will get the focus of the GUI. Can I somehow open it so that it will run in the visual background and not pop up, blocking any ...
4
votes
3answers
434 views

Logout scripts: not completed on shutdown, reboot

I'm trying to do some stuff at logout, and the task can take up to 5 minutes to complete. If the user chooses Power off or Reboot directly, the script is killed before completion. If the user just ...
4
votes
1answer
1k views

Script to add static ip to network interfaces

I've got a little script here that should be pretty self explanatory but I can't figure out why the while loop doesn't handle the functions right. It should show the getinfo function again if the user ...
4
votes
2answers
318 views

Can't add more than eight keyboard layouts

I read this article where is a workaround to add maximum eight keyboard layouts. But my questions are: I would like to try this, but I see they've written there something with "gnome" in the ...
4
votes
1answer
214 views

Why Byobu custom status notification code fail to show in color?

The code below runs well in Bash and shows text with proper green background color but when I add it to the ~/.byobu/bin/ folder it shows the escape characters instead. Something like ...
3
votes
8answers
375 views

How to sort by row from terminal

I was looking at this question and I wondered if the following could be done from terminal. I did it in python, just want to see if it could be done from terminal, bash scripting or whatever. ...
3
votes
5answers
246 views

How do I make the shell to recognize the file names returned by a `ls-A` command, and these names contain spaces?

This is the part of the script I am using to rename the files returned by ls-A: for FILE in `ls -A` do ext=${FILE##*.} NUM=$(($NUM+1)) NEWFILE=`echo $2_$NUM.$ext | sed 's/ ...
3
votes
2answers
261 views

Add strings to a file with commands

I need to add: user_xattr,acl,barrier=1 to my /etc/fstab file. Is there a way to do this via the via shell script? I only want to edit the '/' mount. Here is what I have before I manually edit ...
3
votes
3answers
133 views

Store output of command into the array

This is command: pdc status -a 2>&1 | grep 'okay' It gives the following output [okay ]: you are currently listening: 33 [okay ]: you are currently listening: 22 [okay ]: you are ...
3
votes
3answers
292 views

Extract number from string

When using this ubuntu command: ${HOME}/temp/.git describe --always --tags HEAD the output of this command is: v0.1.5-2-p343h3d3 I want to extract 1.5 from the output above and check if it's ...
3
votes
2answers
2k views

What is the difference between “source x”, “. x” and “./x” in Bash?

I have one bash source run.sh as follows, #!/bin/bash if [ $# -ne 1 ]; then exit fi ... when I execute it in two ways, there are different behaviors. The first way is, source run.sh It will ...
3
votes
1answer
45 views

pkill not killing

I have a Script named PirateRadio.py That I am writing a script for. I need to kill and reload the script. Possibly with the same PID. I thought SIGHUP was a sure thing. when i run #pkill -1 ...
3
votes
1answer
55 views

Ubuntu doesn't calculate expression in [ ..]?

I'm a newbie to Linux. I'm reading the book Linux: Rute Users. Everything is good till I come to Unit 7.1. My script is as follow: #!/bin/sh echo "enter X" read X echo "enter Y" read Y echo "X*Y = ...
3
votes
1answer
155 views

Help Debugging Backup Script

Every 3 hours the script will run and backup a folder "SOURCE" and it will save it along with the other backups of the current day in the folder "month-day-year" e.g. "03-24-13". When a new day comes, ...
3
votes
1answer
655 views

Unable to apply wallpapers

We are unable to apply wallpapers, we are getting the following error. How do i fix it?? Error: Error setting value: Can't overwrite existing read-only value: Value for ...
3
votes
3answers
291 views

Bash Script Difficulty

I'm creating a bash script and I want to create a m e n u. I am a beginner and still a noob but appreciate all your help! When I run the code it displays the menu but the problem is when the user ...
3
votes
3answers
78 views

How to concate strings in a bash script to use in SQL-Statement? [closed]

I would like to do the following in a bash script: read some filenames out of an file with filenames set a variable input path concat 1. and 2. use 3. in sql-statement Here my code: ...
3
votes
2answers
203 views

Anyway to make hotkey to turn screen off?

I was just wondering how can one make a script (or make some changes) by which I can turn screen off in Ubuntu(12.04) whenever I want, the way screen can be turned off in Cellphones. And also I would ...
3
votes
3answers
74 views

How do i find out lines of a file that are not present in another file?

I have two files A and B. I want to find out which lines of file B are not present in the file A. How do I do this? The lines can be at any position in file A
3
votes
1answer
2k views

How to change a directory using shell script?

I am trying to change a directory to home/developer. I used cd home/developer in my shell script. After executing script it is again coming to original directory,where I executed shell script.
3
votes
2answers
18k views

How to run shell script via terminal using ubuntu 13.04?

I just upgraded to 13.04. Before this when I click on a shell script file it'll give an option to run via terminal but now the option is no longer available and when I click the file it'll directly ...
3
votes
1answer
3k views

Why does “if [ 0 ]” execute the “then” statement in bash script?

This guide says: An if/then construct tests whether the exit status of a list of commands is 0 If I execute 0 in the bash, it says: 0: command not found So its exit status is not 0, and [ 0 ] ...
3
votes
2answers
1k views

Creating shortcuts with shell script

I have programed a java program. To run it I write java -jar /path/name.jar in the Terminal. I have made a script (.sh) which installs the program on the system. I want the script to create a shortcut ...
3
votes
1answer
148 views

How to check in a bash script if passed argument is file or directory?

I have to write a simple bash script in Ubuntu which would allow me to pass it some arguments and I want to check if these arguments which can contain spaces are files or directories. How can I do ...
3
votes
1answer
44 views

Call a command as if it were in called in another directory

I'm using a command line program whose documentation states: "You can run XXX on input located in another directory, but its output will always be put in the current working directory". I'd like ...
3
votes
1answer
148 views

Code works in terminal but not in script for renaming (manipulate filenames with spaces)

I want to learn more so I have tried to script more than just using the terminal. I know rename and I can rename image files with rename 's/ /_/g' *.jpg but when I write it in a shell script to point ...
3
votes
2answers
70 views

starting and killing evince process in a loop

I have certain PDF files. I want to inspect each of them for 20 seconds. The way I was trying to do that is like following: for file in *.pdf; do echo $file; evince $file; sleep 20s; killall evince; ...
3
votes
1answer
78 views

Help Understanding Line in .bashrc

I've tried looking everywhere to determine what this line does in my .bashrc. The reason I want to know is because now ~/.pam_environment is recommended. This is the line: [[ -s ...
3
votes
1answer
174 views

Should recursive shell script lock up the system?

I made a typo and ran my shell script recursively. Example: #!/bin/bash # filename: kill-me-please.sh ./kill-me-please.sh This caused my system to become unresponsive and all I could do was a ...