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
14 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
1answer
28 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 ...
2
votes
1answer
68 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
19 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
16 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
32 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
0
votes
0answers
23 views

How to get a variable from a .cfg file and place it to an xml file? [on hold]

I wanted to write a shell script for linux. I will use it for soapui projects of mine. Assume that there is a variable in a.cfg file, a.cfg file #var=1.2.3.4 I wanted to get this variable and ...
1
vote
2answers
137 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
87 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
22 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
144 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
39 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
31 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 ...
5
votes
1answer
109 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
19 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
0answers
44 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
24 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
262 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
28 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
41 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 ...
8
votes
2answers
425 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
126 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
27 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
33 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 [ ...
0
votes
2answers
37 views

replace string in a file with another where both are saved in variables

I want to replace a string found in a file with another string, but both have a special character (in this example it is a . char) e.g 1.0 and 2.0 so this the is command currently used: sed -i ...
1
vote
2answers
27 views

Splitting a string not working

I'm trying to split a string but there is something wrong. If anyone could please advise. echo -e "\e[41m## i = $i ##\e[0m" str1=$i | cut -d'/' -f1 echo -e "\e[41m## str1 = $str1 ##\e[0m" and ...
1
vote
1answer
37 views

shell script not working properly

I'm writing the below script but it seems not to work as this is the output: ## entered first loop ## [==1.0]: command not found [==2.0]: command not found ## entered first loop ## [==1.0]: command ...
2
votes
1answer
27 views

Defining and incrementing a variable in bash

I've something like this: declare -r constant1=0 declare -r constant2=0 for xx in 1 2 3 4 5 6 7 8 9 10 do constant1=$((constant1 + 1)) for yy in 8 7 3 9 3 9 2 8 4 4 do ...
2
votes
1answer
20 views

Logarithmic shell expansion?

I know there is ** for exponentiation in bash. Is there a simple shell expansion for logarithms?
1
vote
2answers
86 views

how to see CPU and memory usage for a program after run it

I wrote a shell script and run it with terminal.script call another programs to run and have some child process. how can i see TOTAL memory and CPU used for that script after run it ? more generaly ...
1
vote
1answer
50 views

transmission-cli connected to peers but not downloading

I'm using my Ubuntu-Server and transmission-cli to download torrents overnight. When I try to download the Ubuntu 12.04.5 Server torrent transmission connects to various peers, but doesn't download ...
-1
votes
1answer
31 views

Command output to file, new lines at top [duplicate]

I'm rewriting some 20+ year old Unix scripts and I want the output to go to the screen and a file. I know this is possible with tee. Is there a similar command that stacks new lines on top, at the ...
0
votes
1answer
27 views

Run Matlab with a desktop launcher

I'm trying to make a desktop launcher for Matlab in order to run it from the desktop. This is how my desktop entry looks like: #!/usr/bin/env xdg-open [Desktop Entry] Version=1.0 Type=Application ...
0
votes
3answers
36 views

Basic Shell programming question with && {

Hi just wondering about the use of && and { } in this example down below, does it mean that if you use the && and follow by { you write a shell script without having to create one ...
1
vote
0answers
9 views

pause process during lockscreen

I used WhatPulse back on windows and got it installed on Ubuntu, too, but now sometimes, when waking up from standby, it expects an internet connection immediately and builds up a lot of ram and ...
2
votes
2answers
43 views

Rotate images from terminal

I have a directory with a lots of image but they are in wrong orientation. I want to rotate the images to correct orientation (mostly ±90o). Using image (shotwell photo) viewer I can rotate ...
0
votes
1answer
63 views

How do i write a terminal script to setup ubuntu for me instead of spending days every time?

From what I understand I can make a text file with all commands same as I would type in terminal, make it executable and run it. Would running sudo mysetup.sh or mysetup.txt be OK so not typing PW ...
1
vote
2answers
49 views

convert with bash - trim/crop and center

i need a fast and reliable way to modify a lot of images. There is a lot of white around my pictures i want to get rid about. The problem is, it is a number of similar pictures, but they have ...
2
votes
1answer
59 views

Can there be two init processes?

I am new to Operating Systems (specifically Linux) and this is my first question here I want to ask, can there be two process with CMD = init (as given by ps - e command). I had two processes on my ...
0
votes
3answers
59 views

Shortcut to execute shell scipt? [duplicate]

I'm trying to create a shortcut that will run a .sh file deep in some directory without having to navigating to the absolute path. I have tried using aliases, which did not work as. Using soft/hard ...
0
votes
0answers
26 views

Reconnecting network through shell script

I've written following code to reconnect to network: #!/bin/bash while [ "$var" != "end" ] do pingtime= $(ping -w 1 192.168.1.107 | grep ttl) if [ "$pingtime" = "" ] then $(sudo ifconfig ...
3
votes
2answers
999 views

What is the difference in running script with ./

What is the difference between running the script by calling directly its name and calling the script by adding a with prefix of './' . I can't find any difference in run time.
1
vote
1answer
73 views

Bash script to remove item from Nginx cache

I have Nginx running in Ubuntu. I'm trying to write a script that deletes an item from the Nginx cache. Script: clear_single_cache_object.sh #!/bin/bash echo "Deleting: " $1 grep -lr $1 ...
9
votes
2answers
142 views

Run only parts of a script as sudo, entering password only once

I am writing a script (actually a combination of scripts and makefile) that installs external dependencies: some apt-get commands, some git cloning, building, installing, adding users to groups, ... ...
1
vote
1answer
36 views

Set up shortcut for different terminal shells

I would like to get some practice using different shells (zsh and ksh, etc...) What is the best way to set it up so I can create a shortcut that will launch a terminal with the desired shell? I'd ...
0
votes
2answers
39 views

Whitespace Problems With Script and Variables

I'm trying to beat my head against the syntax of this. I'm getting problems with whitespaces and I can't see if there's a better way to do this. vardir=/home/user cd $vardir for i in $(ls "$vardir") ...
0
votes
2answers
130 views

Export $DISPLAY value in Shell script

I am trying to Print the value of $DISPLAY under my Shell script. I have Following shell script which Exports the DISPLAY: #!/bin/sh export DIPLAY=:10.0 Here, each time I need to change the Value ...
7
votes
2answers
1k views

Difference between ls -l and ll?

I'm relatively new to programming as a whole and some tutorials have been telling me to use ls -l to look at files in a directory and others have been saying ll. I know that ls is a short list, but is ...
0
votes
1answer
39 views

How to check if a variable is empty on command line? [duplicate]

I have the following shell script echo "please enter user name: " read USER_NAME while [ ! "$USER_NAME" ] do echo "User name can't be empty please re-enter: " read USER_NAME done How can I do the ...