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

5
votes
1answer
93 views

Bash always evaluate Regex as true

In a script, there's these lines #!/bin/bash ... if ! [[ $SCREEN_NAME =~ ^[a-zA-Z0-9_.-]+$ ]]; then echo "The Server title contains invalid symbole. Only a-z A-Z 0-9 - _ . are allowed" exit 1; ...
2
votes
1answer
59 views

Shell script to check url

I am trying to write a shell script to check for the existence of a particular directory in a particular domain name. For example, I have a web site named www.example.com. I want to check whether the ...
6
votes
3answers
69 views

Command equivalents of Unity keyboard shortcuts

I'm wondering is there any way to achieve the affect of the Ctrl-Alt-Keypad shortcuts in Unity using terminal commands instead? I want a command that sets a gui window to half the size of the screen, ...
0
votes
0answers
3 views

QJoypad profile switch on program close

I've just started playing with qjoypad on my ubuntu HTPC. I like it because it lets me use my xbox controller as a mouse, and switch profiles. I've read that xboxdrv lets you do the same, but I've ...
0
votes
2answers
35 views

How to run a shell script on Ubuntu-touch?

I want to run a shell script on my "bq Aquaris E4.5 Ubuntu-Edition" phone in the Terminal App and created a shell script in /home/phablet/Documents/sync.sh #!/bin/sh # sync contacts and calendar with ...
2
votes
1answer
17 views

Reset hibernation delay from command line

My hibernation on Ubuntu 14.04 LTS works fine. But someone keeps changing its delay to never hibernate. I am tired of paying days' worth of electricity for 10 minutes usage a day. Is there a way I ...
1
vote
1answer
24 views

Script that prevents the software to run unless other associate software is already running

I have a situation here. We wanted to prevent a software to run successfully unless the other software is already running. If the script has been run, it run the main software and it will check if the ...
0
votes
0answers
14 views

How to press ENTER in Nano on Ubuntu-touch via abd?

When I'm connected to Ubuntu Touch (bq Aquaris E4.5 Ubuntu-Edition phone) via adb shell and I'm editing a shell script with Nano. How can I press ENTER to save changes? Nano does not accept the ...
0
votes
0answers
16 views

How to autostart a shell script on Ubuntu-touch?

I want to start a shell script on my bq Aquaris E4.5 Ubuntu-Edition whenever I switch on the phone to syncronize my calendar and contacts via syncevolution with my owncloud server. How can I ...
5
votes
2answers
70 views

How do I tell a shell script my password?

I've been trying to create a script that runs sudo apt-get update and sudo apt-get autoremove whenever I log in. It goes like this: #!/bin/bash (sudo apt-get update) (sudo apt-get autoremove) But ...
1
vote
1answer
18 views

Script that put filenames at working directory in text files with some additional strings

I need to make a script that put filenames at working directory (with specifical extension) in text file with some additional strings: For example: if I interested in files with extension "i" and ...
8
votes
2answers
3k 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" ...
6
votes
6answers
292 views

Exit terminal after running a bash script

I am trying to write a bash script to open certain files (mostly pdf files) using the gnome-open command. I also want the terminal to exit once it opens the pdf file. I have tried adding exit to the ...
4
votes
3answers
199 views

How to use double substitution in awk?

To print the fields at 29th column in two files I used paste <(awk -F, '{print $29}' PreRefFile.csv) <(awk -F, '{print $29}' Txlog.csv) This worked fine. To print all the fields starting from ...
0
votes
1answer
22 views

How to compare float variables in awk?

awk -F, 'NR==FNR{c[$29]=$29;next} NF{print $29 ((c[$29]==$29)?" ":",mismatch")}' $file1 $file2 The value of 29th field, i.e., $29 in file1 was 832.9 and that of file2 was 832.9000. If I compare them ...
0
votes
3answers
26 views

Problem when trying to run shell script : No such file or directory

I'm trying to run the following command on bash: ./home/abcdef/Desktop/jikesrvm/dist/prototype_x86_64-linux/rvm which is giving me a bash: ...
1
vote
1answer
1k views

Good shell script to move a file to another location?

I'm trying to write a shell scrip to move a file to a a different location when it's found. And when it's not found to move a file from that different location to its location. This is basically my ...
-1
votes
1answer
44 views

How to create logfile for a bash script?

I've written a bash script that runs multiple instances of a program and would like to write the entire output of the script to a logfile. I tried #!/bin/bash touch <.../somewhere/logfile.log> ...
3
votes
3answers
97 views

Can I call a .cpp program in Bash?

I am new in Bash programming. I want to call my C++ program in Bash file. My program is myProg.cpp: #include<iostream> using namespace std; int main() { cout<<"Salam! ...
2
votes
1answer
34 views

How to make an export DISPLAY?

I'm execution a Java project on a distant server. My project generates a graphical interface. Here is the shell script that I'm executing on the server side : export ...
13
votes
1answer
617 views

opposite of eject command?

I have a ton of CDs to image, and I just got curious. I can eject with the eject command. What command inserts the disk tray back into the CD drive? yes it is the type that can pull the tray back in. ...
5
votes
1answer
108 views

How to get the tags for the installed software in ubuntu?

I can retrieve the softwares using the dpkg command but is there a command to get the associated category for the software . For example if I have Firefox installed can I somehow retrieve a tag for ...
1
vote
1answer
214 views

xbindkeys scripts to toggle WiFi and Bluetooth devices ON/OFF

I need scripts for toggling WiFi and bluetooth (2 scripts) on/off. I want to use them with xbindkeys. I searched the web, but failed to find it. I have found a script for WiFi about a year ago, but I ...
0
votes
0answers
19 views

How to store last email in a file?

I wanto to set my bash detecting incoming e-mails and maybe execute commands in the emails, detecting programmed regular expresions, what commands does let me to do this? I'd like to have a solution ...
1
vote
3answers
35 views

Force “bad” (not 0) return code of terminal command?

I have a framework written in python, and for testing purposes I basically want to do a subprocess (aka shell call) ... that should simply come back with a RC != 0. I tried to invoke some non-existing ...
4
votes
3answers
7k 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 ...
4
votes
3answers
264 views

improve bash script

I have a quad core desktop, and i wanted to know the average temprature according to sensors. so i wrote this bash 1 liner. echo `sensors -A | awk {'print $3'} | sed 's/+\|(crit\|0:\|°C//g'` | awk ...
1
vote
1answer
96 views

One command for ls and cat functionality?

Okay guys, this is an experimental question warning! I often confuse cat and ls when quickly working on the console. Not because I forget their meanings, no. Just because I type without deeply ...
0
votes
1answer
26 views

how to stop using export command

every time I run gdb I have to type export SHELL=/bin/bash or gdb would return exit with code 127 my question how to make this command run every time automatically without need to re type it because ...
30
votes
4answers
2k views

When to use () vs. {} in bash?

I'm studying shell scripting with bash and I need to know the difference between (...) and {...}. How does one select between the two when writing a script?
5
votes
3answers
4k 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 ...
0
votes
1answer
35 views

How to save working directory in gnome-terminal?

How can I save the current working directory in different tabs in a gnome-terminal? I am looking for a script or a command, that will save the working directory of each open tab, without having to ...
4
votes
1answer
63 views

How to detect keystrokes?

I have a script running always at the background. Inside that script I have to write the codes to detect keystrokes, and once a particular keystroke is detected, the rest of the script must be ...
0
votes
2answers
65 views

How to make the terminal prompt make sound every time i am prompted to write a command?

I want every time i have the command prompt (i.e, end of a command) to get a sound to get attention to the terminal [as i am using laptop \a character is not going to work with me]. The command i want ...
1
vote
2answers
36 views

Writing script for automatic process

My shell is bash and I need to write a script that runs a specific software for each input data in the several folders. For example: gd2p.pl -i /home/WORKDIR/folder1/input1.o Let's say that I have ...
0
votes
1answer
37 views

Open up new terminal and run script with double click in Unity

I want to execute expect -c " spawn ssh user@10.0.0.0 expect \"assword:\" send \"pass\r\" interact " in a new terminal by doing double click in an .sh script. I tried ...
2
votes
1answer
34 views

ip netns monitor not working in a script

I'm trying to use ip netns monitor in a script to react to the creation of new network namespaces, eg: ip netns monitor | while read ACTION NETNS; do echo 'handling it!' done However I never see ...
2
votes
1answer
23 views

Run shell script on keyboard shortcut

I would like to run a shell script on the press of a button. The script works if I run it like usually: sh script.sh. But assigning a shortcut to it doesn't work. How would you do this in Xubuntu ...
1
vote
1answer
32 views

Error: object “ip” is unknown , try “ip help”

I am trying to run trusted executables through a script. I copied the binary executable /bin/ip to a directory called Tools. I renamed the binary to eip. I have navigated to the directory tools and ...
0
votes
2answers
41 views

Can i make a commad execute in background without producing any output?

Is there a way or an option to make a command run in the background without the need to wait for it to end to get the prompt back? (just like mplayer command to play a music file in the background and ...
0
votes
1answer
19 views

Why output redirection is not working with the mplayer command?

The mplayer command is used to play a media file in terminal or a shell script and i gives some controls over it like move forward, backward in the file, etc. Sometimes i find it annoying so i want it ...
1
vote
1answer
9k views

The setenv command is not found when trying to run a shell script. How do I fix this?

I have a problem with a shell script, which looks like: #!/bin/csh -f setenv Test The problem is that it worked until I installed Ubuntu 12.04. The respond tells me that the command setenv is not ...
0
votes
1answer
27 views

watch internet connection thoguh shell

I just need to run a shell script when an internet connection is available. Is it possible to watch the internet connection arability through Shell scripting. ping google.com is the easy command to ...
0
votes
2answers
43 views

How to highlight second vowel from every word in a file?

I am trying to highlight every second vowel in a word to the colour red. What am I doing wrong? cat room.txt | sed 's:[AEIOU]:$(printf "${\e[1;30m}&${\e[0m}"):i2' Ps. Sorry for making it ...
1
vote
1answer
39 views

cutecom not comunicating

I need some help communicating with a serial port device. I have the serial port set to "auto" IRQ in the BIOS. The device (a Temperature controller) has the following Data protocol: Baud:9600 Tx ...
3
votes
1answer
85 views

What are the differences between executing shell scripts using “source file.sh”, “./file.sh”, “sh file.sh”, “. ./file.sh”?

Have a look at the code: #!/bin/bash read -p "Eneter 1 for UID and 2 for LOGNAME" choice if [ $choice -eq 1 ] then read -p "Enter UID: " uid logname=`cat /etc/passwd | grep $uid | ...
1
vote
1answer
23 views

Bash script behaves fuzzily

I'm using this bash script to check if the content of two paths install and install1 passed as arguments is the same: #!/bin/sh du -a $1 | grep -Po "[0-9]+\t$1/\K.*" | sort -n > list.txt du -a $2 ...
0
votes
1answer
41 views

How to accept root password through shell script

Is there any way that I can provide root password in the shell script without explicitly entering it through the terminal
1
vote
1answer
37 views

Data transfer between two remote servers linux (sftp)

I work remotely trough my Linux system. I have data on server A which can be accessed only through SFTP. The second server is an HPC cluster. I want to fetch data in my HPC cluster working directory ...
1
vote
2answers
175 views

How to send a mail/write to other user through a shell script? How to send EOF?

if [ who | grep $user | grep pts ] then write $user message here EOF fi Here if I execute it, it is blocking at write and I have to enter a ...