A script is a sequence of commands or instructions that are executed by an interpreter program rather than compiled into a standalone executable program.

learn more… | top users | synonyms (1)

4
votes
2answers
20k views

how can I add (subtract, etc.) two numbers with bash?

I can read the numbers and operation in with: echo "First number please" read num1 echo "Second mumber please" read num2 echo "Operation?" read op but then all my attempts to add the numbers fail: ...
3
votes
2answers
674 views

How to copy multiple files but keep their extensions the same?

I am looping through a number of files, and $file represents the current file. How can I make copies or renames and keep the extension the same for this current file? e.g. if $file = x.jpg How to ...
1
vote
3answers
822 views

How to add Multiple Searches in AWK command

Im trying to search for the files Created in June,July and August months. I used this method ls -lrth|awk '/[Jun][Jul][Aug]/ {print}' but it ain't working. Please help me correct the syntax.
2
votes
3answers
233 views

Analyzing tricky one liners & having handy list of useful ones

Have seen one liners like below & took a little time to analyse exact use & working of it – something like set the value to later one if it is not set. export ...
1
vote
2answers
73 views

(Ill)Logical statement

I am attempting to make a simple script to flip my computer screen. My first if statement executes perfectly, but after that, thought $istouch is "on", the elif statement block will not execute! I ...
2
votes
1answer
98 views

Regular Expressions within a string in AWK using if/then control structure?

PROBLEM I want to specifically use AWK (GAWK, MAWK, whatever) in an AWK script to sum up the values in field 9 for every record that contains "runner__.jpx" (the underscores are placeholders for two ...
0
votes
4answers
134 views

Create a duplicate record based on a condition

I need to write a shell script where I have to create a duplicate record based on a condition and then change the value in a column of the new row which will be created. I am trying to create a ...
1
vote
2answers
2k views

Bash shell scripting basic question regarding the syntax and basename

Consider the script below: myname=`basename $0`; for i in `ls -A` do if [ $i = $myname ] then echo "Sorry i won't rename myself" else newname=`echo $i |tr a-z A-Z` mv $i $newname fi done ...
5
votes
3answers
862 views

Maintain (or restore) file permissions when replacing file

I have a command that accepts a file as an argument, modifies the file, then writes it to the file name specified in the second argument. I'll call that program modifyfile. I wanted it to work "in ...
4
votes
3answers
1k views

Summing up an array inside of awk?

I have the following piece of code: sum1= sum2= declare -a a echo $temp | awk '{split($0,a,","); name=a[1] ; for(i=2;i<=4;i++) sum1+=a[i] ; for(i=5;i<=7;i++) sum2+=a[i] }' This code is ...
2
votes
1answer
82 views

Configure add-to-tranmission-daemon-action in firefox?

How do I configure firefox such that a clicked bittorent link is automatically added to a transmission daemon that runs on a remote machine? The transmission daemon is available via ...
2
votes
3answers
2k views

Shell script to validate mount point status in the linux server

I'm in need of a script which should work as below. A script where it would validate if that specific mountpoint is currently mounted on the server. It would search for mountpoint name in /etc/fstab ...
2
votes
3answers
118 views

Using sed to insert latex commands around headers of a document

I have a documen with headers in ALL CAPS, for example: NAME env - run a program in a modified environment and I want to insert \item[ before the header and ] \hfill \\ after a header ...
3
votes
1answer
169 views

How can I write a sed script to delete numbers from a line?

Sample File a.b.gg3d 0000000001 0000000001 y a.b.112a 0000000000 0000000001 y a.b.gg3s 0000000001 0000000001 y a.b.1111 0000000000 0000000001 m I have a file that includes about three thousand ...
0
votes
1answer
932 views

How to run a shell command in a server?

I am fairly familiar with computers and web stuff but this is a bit out of my comfort zone. I have a shell script (.sh file) I want to run in a Linux server I have one site hosted (the script is a ...
2
votes
1answer
4k views

bash: integer expression expected

I have a file out.csv I have to check if the name inputed by user exists in the file(comma separated) or not. I am taking name using read but while checking for equality I am getting error ...
1
vote
2answers
93 views

How can I merge multiple lines with spaces (blank line) separating them? [closed]

I'd like to merge the following multiple lines of output so that they form a single line: line 1: ...
3
votes
2answers
1k views

How to get volume level from the command line?

I have a text status bar on a tiling window manager and I am using tcl to feed information to it. At the moment I need a command line that output the volume level 0% to 100%. I am using Arch Linux.
5
votes
2answers
512 views

Launching an external script with source command

I've been learning shell scripting, by reading good tutorials and reading scripts. I was reading this minecraft init script, and these first lines hit me: if [ -L $0 ] then source `readlink -e ...
1
vote
3answers
229 views

how to calculate the average value of the column that have the row ID?

I want to calculate the average value of my data when they have the same ID (in my specific case, the same day but different time in a day). This is meant to calculate the daily average value of my ...
0
votes
3answers
101 views

how to run more than one program in a single script?

I have about 6 programs I want to run one after the other. They all are in different directories with their respective data. I would like help with a script that I can use to run each program in a ...
2
votes
2answers
95 views

open a file and copy the listed files to another folder

I have a file named file1.txtcontaining file names like below : filea.txt fileb.txt filec.txt I want to copy the files listed in file1.txt to another folder. What is the UNIX command to use? (the ...
1
vote
1answer
967 views

Press a html button via shell script?

i am currently trying to write a script to change some parameters on a webpage via a shell script. I can change the values in the textboxes without any problems, but i can't seem to figure out how i ...
2
votes
4answers
208 views

Adding values of the column that have the same data ID?

I want to prepare a uniform daily data from a mixed daily and sub-daily data by adding the sub-daily values and producing a uniform daily data. My sample input and desired out put data looks like ...
1
vote
2answers
58 views

how to duplicate values of each row under each for n times? [duplicate]

I have daily data which I want to duplicate in to 24 hours data keeping the value the same for the hourly time step. My data looks like: day Value 01/01/2012 2 01/02/2012 3 Then I want the ...
3
votes
0answers
881 views

How do I reset a USB device using a script?

I have a USB GSM modem that does not always work property (Huawei E367u-2) Sometimes it gets reset (USB device disconnect/reconnect in logs) and when it comes back up, it has different ttyUSB numbers. ...
4
votes
4answers
3k views

Capture output of a bash command, parse it and store into different bash variables

Explanation: I have a small bash script which simply runs any Linux command (e.g. say ifconfig) The typical output of ifconfig is something like this: eth0 Link encap:Ethernet HWaddr ...
0
votes
3answers
112 views

selecting rows that have the same value [closed]

I have a problem in selecting rows that have the same value. My data is too huge to go row by row to do that. I want you guys to let me know scripts that can perform this. My data looks like as ...
1
vote
2answers
2k views

how to select, copy columns of different file to form new files

I have four files each contain daily station data. file 1: prec file 2: minT file 3: maxT file 4: wind Here prec, minT, maxT and wind are files that store values of prec, minT, maxT and wind for ...
19
votes
3answers
3k views

Does the shebang determine the shell which runs the script?

This may be a silly question, but I ask it still. If I have declared a shebang #!/bin/bash in the beginning of my_shell_script.sh, so do I always have to invoke this script using bash ...
0
votes
1answer
310 views

Similar method to /etc/init.d

I have set my script to run using the /etc/init.d method. All works good. The problem is that my script does packet capturing and when it restarts the machine after say the crond is loaded then it ...
6
votes
1answer
289 views

Capabilities for a script on Linux

If I want to set a capability (capabilities(7)), such as CAP_NET_BIND_SERVICE, on an executable file and that file is a script, do I have to set the capability (setcap(8)) on the interpreter starting ...
1
vote
2answers
212 views

Why the inconsistency with using cat vs. echo piped to this sed command?

Inspired by this question: sed: N command does not read single line I wanted to understand why there appears to be an inconsistency between the following 2 commands: #1. echo This command produces ...
1
vote
1answer
814 views

Script Command without Junk Character

I'm Using Unix script command to record everything which is output to the terminal and place it in a log file. but when I see recorded file, it also include Junk Character. So how to record terminal ...
1
vote
2answers
352 views

Moving Older Version Files to another folder via a script [closed]

I am trying to find a way of getting my cmd script to look through my folder, find the older versions of the pdf docs in the folder and move them to another folder called older versions. Problem I am ...
3
votes
2answers
767 views

Zip folder without including path to folder and require only one argument

I'm trying to make a zip function that'll do all the steps I typically do when zipping a file or folder. Say my current directory is ~, and I want to zip a folder named Folder1, whose file path is ...
3
votes
2answers
546 views

screen /bin/bash execute script and then go to interactive shell

I am using .byobu/windows to start up some screen sessions, and I'm trying to start a script that will exit to an interactive shell once it has completed. Is this possible? I've tried: screen -t ...
3
votes
2answers
143 views

bash equivalent of zsh's $@[2,$#]

(NB: the motivation for this question is only to improve my bash programming know-how.) I want to know the bash equivalent of zsh expressions such as $@[2,$#], which directly address a range of a ...
1
vote
3answers
101 views

Confused on user and su in linux

How could I run a script as a specific user (non-root)? As this? sudo su - john /usr/share/script.pl for user john?
6
votes
4answers
2k views

Bash script to rename files from a text file source

I'm fairly new to bash; I can just about perform simple administrative tasks with simple commands 1 at a time. However, I've been tasked with renaming some files in a directory using a text file as ...
1
vote
3answers
152 views

Taking Backup of files of particular limit in unix

Here is the scenario, I have 1000 files in a folder each ~3 MB. I want to zip all files into 50MB each zip and remove the original files. NOTE: 50MB may contain 20 files or 10 files but that zip ...
0
votes
1answer
978 views

if condition, loop in grep [closed]

Could someone please provide help for me. I tried to start writing a shell script but am getting hung up with this issue. I need to grep commands "adb shell ps" and find in it 3 processes with names: ...
2
votes
2answers
7k views

Checking and changing file permission with script

I'm new to bash and I can't get a script working. This is the code that I have: #!/bin/bash file=~/scripts/text.txt if [ -e $file ] then echo "The file exists" elif [ ! -e $file ] then echo "The ...
2
votes
5answers
200 views

List a directory but only if it contains sub-directories?

In Unix, is it possible to use one command ONLY to list directories if they contain a sub-directory? For example, I would like to list the directory name if it contains a sub-directory called ...
1
vote
1answer
195 views

Is it possible to have comments in multiline commands in fish?

In bash it's possible to do my_function() { echo "hello" | #remove 'l' tr -d 'l' } but in fish ( http://fishshell.com ) I wasn't able to do the same: function my_function echo "hello" | ...
1
vote
0answers
322 views

gnome-terminal cmd leaving processes open after closing parent window

The following simple command should demonstrate my issue: gnome-terminal --tab -t "Tab 1" -e "/bin/bash" --tab -t "Tab 2" -e "/bin/bash" This should open a new window with two tabs and an active ...
5
votes
2answers
735 views

Is there a way to simulate a “Close” event on various windows using the terminal?

I answered on Ask Ubuntu Quit all instances of gnome-terminal via a command but as you all can read gnome-terminal didn't seems to have a SIGcall I could use to simulate this "Close" event. So this ...
1
vote
2answers
972 views

While reading from a file, choose specific fields and compare them with another file in Unix bash?

I have a CSV file that contains the columns a,b,c,d and e and another file that contains column z. While reading line by line from the 1st file I want only fields c and d and at the same time I want ...
5
votes
2answers
187 views

How to assign shell command to key?

I want to assign my script to special key on my keyboard. xmodmap recognize this key as XF86AudioMute, but I want to execute my script when it pressed. How to do it? My window manager is Window ...
2
votes
2answers
330 views

Looping over a folder enter anyways the loop

When looping on a folder through a for f in $path I am experiencing an unexpected behaviour, i.e. the loops is entered anyway even if no file match the wildcard. I am using cygwin and this is my ...