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

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
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
308 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
46 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
454 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
134 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
43 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
42 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
30 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
112 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
90 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
35 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
41 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
37 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
12 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
58 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
66 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
73 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
68 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
70 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
28 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
1k 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
85 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
166 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
38 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
40 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
268 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
2k 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
45 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 ...
0
votes
0answers
65 views

How to change another user keyboard layout silently?

I'm working to automate development environments with Vagrant which manages Ubuntu Desktop 14.04 VMs. My Vagrant script: Creates the VM Setup a new user account based on the host user account Does ...
0
votes
1answer
31 views

Things That Can Be Made In Shell Script? [closed]

So I just started using shell scripting, and was wondering what type of programs you can create. I want to continue using shell script, but if it doesn't lead to anywhere particularly useful I ...
0
votes
2answers
61 views

How do you create a shell script?

I need to create a shell script that will create a user then put it into a group. How do I do it?
1
vote
1answer
18 views

package “state” vs “selection state”

All answers that I read, suggest listing/saving package selection states. i.e. dpkg --get-selections But the selection state could be different from actual. So why use that? Is it just because ...
-1
votes
1answer
33 views

Do something in terminal that involve changing user [closed]

I want do something in terminal that involve changing user like: sudo su do something do something exit do something do something sudo su do something do something exit I've tried to do something ...
1
vote
1answer
47 views

My script only opens new terminals when the previous command's terminal is closed

Sorry if my title is a little hard to understand, I tried to condense the issue as much as possible. I'm trying to run a bash script which opens a new terminal for each major command, that way I can ...
1
vote
1answer
89 views

While Loop Syntax Error

I'm attempting a modification of apt-fast to support parallel downloading and installation. I'm having some trouble with this loop: get_install(){ while ((!${pkg}-finished)) do if [ "$CURNUM" -lt ...
0
votes
0answers
50 views

Script to install software after clean install

I apologize for opening a new thread on this, as I am simply asking for a bit more info on this post Creating a script to install software after a clean install? -- but I don't have enough reputation ...
3
votes
1answer
148 views

How to display all services and version that runs on a host?

I am trying to display all services and their versions that runs on a host using ports from 1 to 1023, in this way: ssh, OpenSSH 5.9p1 Debian 5ubuntu1 (protocol 2.0) smtp, Postfix smtpd http, Apache ...
0
votes
2answers
183 views

How to read user last email using a shell script?

Let's say I have two machines A and B On A I have installed and configured a SMTP and IMAP server For example I have user: george with password: 123456 on Machine A I am trying to write a shell ...
2
votes
3answers
45 views

How can I refer to all files that are named using two numbers?

I want to make a shell script that downloads all files that area named [0-9][0-9].png; e.g: 00.png 01.png 33.png 91.png etc files = ??????? for file in files do curl ftp://server/${file} done ...
1
vote
1answer
63 views

Get results from PHP pages after login [closed]

I have 10 php files like 0.php , 1.php, 2.php etc All those files contains an auth form which send two inputs username and password to itself via post. After login there is a message displayed. I ...
3
votes
4answers
583 views

Is it possible to create commands, put it in one file and run without “./”? [duplicate]

If I create a script in a file like this: #!/bin/bash echo "test" As far I know (as a newbie) is to put it in some folder then make it executable with chmod +x myscript and then execute it with ...
0
votes
0answers
28 views

ftp in script is asking password though the password is in script

Previously the below script have not asked password when execute but all of a sudden it is asking password. I have tried to pass the username, password and server name in single quotes but still it is ...
-2
votes
1answer
40 views

How does this lowercase expression works in bash

I want to convert a vaiable value to lower case. To do this, I am doing following lower_case_var=echo ${var,,} Above expression works fine. However, I am wondering that how it works?
2
votes
4answers
643 views

Why is this Bash script not working?

I wrote a small Bash script so that the image in the folder becomes the wallpaper: for f in *.jpg do gsettings set org.gnome.desktop.background picture-uri file:$f The error is: ./wall.sh: ...