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

0
votes
0answers
11 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 ...
3
votes
0answers
34 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 ...
4
votes
3answers
174 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 ...
6
votes
5answers
245 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 ...
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
20 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
votes
1answer
40 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> ...
0
votes
1answer
31 views

If-then in script [closed]

When i use the if-then statement in my script to put a condition. the condition says "$1 should be between 33 and 70". Any idea how to do that?
-1
votes
0answers
28 views

Ubuntu shell script replace chars at position [closed]

I am making a hangman like game . where I've created the following pseudocode for : solution="solution" answer="........" guess(){ if($1 in solution) replace . at position with letter } So ...
0
votes
0answers
18 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
34 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 ...
12
votes
1answer
610 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. ...
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 ...
0
votes
1answer
25 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 ...
29
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?
0
votes
1answer
33 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 ...
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
33 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
32 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
22 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 ...
0
votes
2answers
62 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
1answer
30 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
40 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 ...
2
votes
1answer
33 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 ...
0
votes
1answer
26 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 ...
3
votes
3answers
94 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! ...
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 ...
1
vote
1answer
37 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 ...
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
2answers
171 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 ...
3
votes
1answer
132 views

Open URL in default browser (Chromium) from terminal and give browser focus

I am trying to open an URL from the terminal window in my default browser which is Chromium: $ xdg-open 'https://www.google.no/?gws_rd=ssl#q=site:askubuntu.com+xdg-open' >/dev/null This will ...
1
vote
0answers
36 views

How to customize the font style in notify-send?

I am trying to change the format of text appearing in pop-up notification while using notify-send command. Here I saw that it can be done using HTML formatting. But that doesn't seem to be working for ...
1
vote
2answers
155 views

Is there any way to execute a shell script whenever I open a terminal?

I want to display a message showing "welcome to terminal" whenever I open a terminal. Any ideas?
1
vote
1answer
43 views

How can I print a variable to a file?

How can I print the contents of a variable into a text file? For example, I have the following script: #!/bin/bash #My Bash echo "saisir votre nom" read $name I would like to print the contents of ...
1
vote
1answer
36 views

How to move all subdirectories to current directory?

I'm new to shell script programming. Suppose we have a file hierarchy like this: /A/B/C/D /A/B/E/F/G /A/H/I /A/H/J/K Note that here we not only have /A/B/.., but also /A/H/.... All letters are ...
6
votes
1answer
136 views

Shell scripting bash: How to detect Alt+N keystroke?

I want to write a script that always listens in the background and execute a particular command when the user hits a specific key combination such as Alt + N. How this can be done?
0
votes
1answer
20 views

Website Files Permissions

I am trying to set all folders and subfolders (directories) to 755 and all files that are contained by folders and subfolders to 644. I don't know how can I do this from 1-2 commands. Is this even ...
4
votes
1answer
62 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 ...
1
vote
1answer
34 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
1answer
42 views

concatenate the argument of date into one string

my main program takes a time stamp having the format of the date as well as the time, separated by a comma, but it is still one string and one argument: #source main.sh '2015-02-10 00:00:00' Now, I ...
0
votes
4answers
304 views

bash script which checks input to see if it is “y”, “n” or other - not working

I have written this bash script which is meant to check your input to see if it is y, n or something else (this will be part of a larger project): #!/bin/bash echo "Have you updated the PATH ...
0
votes
1answer
29 views

confirm a default answer using read after a few seconds [closed]

I want to wait 3 seconds for the user to answer no. if so, then the process exits, if either user answers yes to the prompt or 3 seconds passes then y is given automatically to the question and the ...
0
votes
1answer
45 views

for loop over character array gives unexpected “(”

I am a bloody beginner in bash scripting and I am sorry if the following is very simple. The error I get is: 4: Syntax error: "(" unexpected I am basically trying to run the following in bash on a ...
9
votes
2answers
450 views

Case sensitivity in shell scripting

Consider this Bash script: #!/bin/bash echo Enter any character read char case $char in [a-z]) echo Lower case letter ;; [A-Z]) echo Upper case letter ;; [0-9]) ...
1
vote
1answer
131 views

Copying contents of subdirectories in their parent directories

I have a list of jpeg files in a directory like this (below is just a sample, like the structure is the same but this there are many fo0# sub-folders, not only fo01 and fo02, where each of these ...
3
votes
1answer
31 views

How can I set up ubuntu to switch back to English after a few minutes of inactivity?

I'm using Ubuntu for several years now and enjoy it immensly. I'm developing software in PHP and Javascript for a living. The only minor annoyance I have is that I would like the PC to switch back ...
2
votes
1answer
40 views

Shell scripting : Change in input stream not working as desired

I'm trying to create a shell script that can count words and lines in a file. (yes, I know you can do that using wc, but just for the sake of learning loops) Code echo "enter filename" read f if [ ...