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

13
votes
3answers
19k 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 ...
11
votes
2answers
22k 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 # ...
1
vote
1answer
1k views

How to make a shell file execute by double click

I have tried right clicking on the file selecting properties and then the permissions tab and setting it to execute. However, when I double click the file it opens in gedit. What do I do?
3
votes
1answer
8k views

How to make a file executable? [duplicate]

How can I make my file so that I can double click on it, and it runs. It is a .sh script, but I also have files that say: executable (application/x-executable) in the description of what they are. ...
3
votes
4answers
224 views

What is this line at the top of many files?

I have seen many files which have this line as the first line in them. What exactly is this? #!/usr/bin/env python What does it mean? Why is it necessary?
15
votes
6answers
2k views

Renaming hundreds of files at once for proper sorting

I have a ton of files, all named stuff like 1.jpg, 2.jpg, 3.jpg, and so on up to 1439.jpg, however, I have a problem with one of my projects and alphabetizing. It will usually go in the order 1.jpg, ...
23
votes
3answers
2k views

Where should I put my script so that I can run it by a direct command?

Where can (should) I put my (bash) script so that it can be used (forever) by terminal or by a direct command: Alt+F2? I know there is /usr/bin and /sbin & /bindirectories but when should I use ...
7
votes
2answers
16k views

How do I run 'sudo' command inside a script?

To do a patch manually I must type this command sudo ./playback_delete_data_patch.sh 09_delete_old_data_p.sql There is a space just before the 09: sudo ./playback_delete_data_patch.sh [space] ...
4
votes
1answer
3k views

How to run a command at login?

I need to run the following command (with real parameters) after login: ssh -f user@example.com -L 54321:example.com:54321 -N I need it only for my user, not all users on the machine. Also, I need ...
0
votes
1answer
305 views

An alternative to init.d?

Is there an alternative to Ubuntu's init.d? Like a way of starting and stopping daemons that don't require those monstrous init.d scripts: # cat /etc/init.d/skeleton #! /bin/sh ### BEGIN INIT INFO # ...
4
votes
1answer
1k views

How to pause with specific time between two command in script?

I want to do such as following: #!/bin/bash command1 pause 30 seconds command2 exit This is only example script with pause of 30 seconds between run of 2 command. How to do this?
3
votes
5answers
451 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/ ...
1
vote
1answer
49 views

How to assign a keyboard shortcut to show an Ubuntu Desktop notification?

What I am trying to do is, I have a few texts in a file & when I tap a key combination like ctrl+Q, the text should appear as a notification on my Ubuntu Desktop. What is the command to assign ...
0
votes
1answer
200 views

How to fix invalid identifier error after setting environment variables?

I'm trying to setup cocos2dx in Ubuntu 14.04 LTS but after setting the environmental variables (in .bashrc) I start getting this error: bash: export: dev/cocos2d-x-3.2/tools/cocos2d-console/bin': not ...
-2
votes
2answers
294 views

How to write a script to “listen” to battery status and alert me when it's above 60% or below 40%?

I want to make a tool that alerts when battery is below 40% or above 60% so I can start/stop charging accordingly. I know some tools alert when battery is low, that's not enough. Is there a tool ...
13
votes
4answers
3k views

What does /dev/null mean in a shell script?

I've started learning bash scripting by using this guide: http://www.tldp.org/LDP/abs/abs-guide.pdf However I got stuck at the first script: cd /var/log cat /dev/null > messages cat /dev/null ...
6
votes
2answers
419 views

Execute command from file in current shell

I want to executed command from file (which is script) in current shell in terminal. Example: I have file ch_dir contains following: #!/bin/bash cd /usr Now if I execute file usually as following ...
6
votes
1answer
103 views

Executing a script when inserting a flash drive

How can I write a script that fires on an event? When I insert an USB flash drive, Ubuntu mounts it and automatically opens Nautilus. When this happens with a specific flash drive, I'd like to open a ...
6
votes
2answers
49k views

HTTP POST and GET using cURL in linux

I had server application in asp.net in windows in that i had a web service for that . how can i call web service in ubuntu using shell script by using cURL command
5
votes
3answers
421 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 ...
3
votes
2answers
3k 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 ...
9
votes
2answers
1k views

What does the first '.' mean in '. ~/.bashrc'? [duplicate]

I saw a post about fix your alias in .bashrc. And he says after you put your alias in .bashrc , you need to use: . ~/.bashrc I do not quite understand what the first dot(' . ') does here. What's ...
4
votes
1answer
2k views

Hourly GIT Push

Is it possible for me to automate a Git push every hour via a batch script. I would typically type in this: git add * git commit -m "latest update" git push ...
4
votes
3answers
601 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 ...
0
votes
2answers
805 views

Where to start in Linux programming [closed]

I am a student and I would like to study all these terminal stuffs and all. You all will be experts in this subject. I would like to know where did you all begin and what must I do to be an expert in ...
7
votes
2answers
347 views

Batch files renaming w/ filename's shift

I have a ton of files named this way: [name]_[phonenumber]_HH-mm-ss_dd-MM-yyyy.mp3. How can I shift [name] and [phonenumber] to the end of file name, and put the date in the beginning in form of ...
4
votes
8answers
600 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. ...
2
votes
3answers
2k views

Extracting a part of a massive csv file from command line

I want to read parts of a big csv file between rows n and m and between columns p and q. Is there an easy way to do this easily with the shell? (Are there commands I should read the doc's? otherwise, ...
4
votes
4answers
342 views

Getting values from variables - bash script

I am trying to write a bash script to print values of the 3 variables. Keep getting errors. What am I doing wrong? INPUT1=/tmp/dir1 INPUT2=/tmp/dir2 INPUT3=/tmp/dir3 for i in 1 2 3 do echo ...
3
votes
1answer
786 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 ...
2
votes
1answer
137 views

Execute command with relative (upper) path. Using another working directory

I need to run an application (msp430-gcc) using a relative path from a makefile. The issue is that the application is in a different folder branch so I need to do something like this: ...
2
votes
1answer
6k views

Add cron job on startup from a script

I would like to add a command to be run at startup from within a shell script. For example, I run the script once and it adds the cron job, so from that time on, each time the OS starts, a specific ...
1
vote
1answer
143 views

Shell script to run VM [duplicate]

I use Virtualbox. Instead of clicking on the button of the name of the virtual machine to run it, I want a shell script that can run a Windows XP virtual machine hosted on Ubuntu machine. Can someone ...
1
vote
3answers
1k views

ubuntu 14.04 + gnome 3.10 + gnome-shell restart

Is there a way to ask gnome-shell to run a shell script every time it starts? (Like after a Alt+F2 then r, not on Login) NB: If you think it's about the start-up list, it's not : do a Alt+F2 then r ...
1
vote
1answer
136 views

How can I remove an entry from a list in a shells script?

I have the following script: #!/bin/bash # Bash Menu Script Example PS3='Please enter your choice: ' options=("Option 1" "Option 2" "Option 3" "Quit") select opt in "${options[@]}" do case $opt ...
1
vote
1answer
72 views

ffmpeg-video trim from the end of the video

I have some videos of different duration.I want to cut(remove) the last 5 seconds of all videos.Can i use 'ffmpeg' in a loop to trim the videos?please help me.
0
votes
2answers
151 views

shell script not running on terminal

I created a scriptA.sh on the desktop and make it executable then this was it content: #!/bin/bash sudo -u userA bash -c 'PACKAGE_PATH=/home/userA/package1; cd /home/userA/scripts' I want to double ...
0
votes
0answers
52 views

How to open reverse shell from NOWASP?

I'm using 12.04 LTS and the server is 12.04 LTS server. So, I'm teaching myself some pen testing and right now I'm trying to use netcat to open a reverse shell from nowasp, my nowasp is on a VM and ...
0
votes
1answer
540 views

Execute script in sh mode instead of bash in Shell

I added my script called mylovelyscript.sh to /bin/ folder. My script contains code that echos text with different text colors. But when I run my script like $ mylovelyscript it executes in bash ...
0
votes
1answer
5k views

Compilation error when installing Realtek 8192cu driver

I'm using a laptop with Ubuntu 13.04 64 bits. After "fighting" for some time, I gave up trying to have my Realtek 8188ce wireless card work properly (the wifi connection is annoyingly unstable). So I ...