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)

0
votes
4answers
152 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
1k 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
2k 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
94 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
4answers
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
130 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
185 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
1k 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
99 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
2k 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
649 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
270 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
111 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
107 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
1k 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
240 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
62 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
954 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. ...
5
votes
4answers
4k 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 ...
1
vote
3answers
118 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
4k 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
347 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
350 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
255 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 ...
2
votes
1answer
988 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
380 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
868 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
597 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
145 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
103 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
174 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
1k 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
8k 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
227 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
236 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
329 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
922 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
1k 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
207 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
409 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 ...
1
vote
3answers
234 views

Launching shell script from SSH and disconnect

I have a script which I run from SSH that launches several processes which I would like to keep open when I disconnect from my session. Is that feasible? Launching the script in background is not a ...
4
votes
1answer
268 views

Ubuntu unattended install : echo keypress to dialog

Ubuntu 12.04 LTS Server 64 My unattended-mode bootstrap.sh script contains: apt-get upgrade -y I know that during execution a primitive UI for GRUB installation will be shown which requires ...
2
votes
5answers
928 views

Why is the first line comment of .sh file necessary? [duplicate]

I was told that the first line shebang (#!/bin/bash) is necessary in the shell script file, and the file won't run accurately without this line. But I tested some scripts. They work just fine without ...
2
votes
2answers
424 views

How to set a variable equal to the output from a command in GRUB2?

I want to customize a little my GRUB 2 bootloader, so I'm asking how can I set a variable equal to the output from a command in GRUB2? I am interested to pass the output of date command to a ...
3
votes
2answers
4k views

Javascript to HTML converter?

Take for example this snippet of code on a web page. <html><body> <script language="javascript"> document.write("The cat"); document.write(" sat on the mat"); </script> ...
2
votes
1answer
216 views

Passing values to a parameter in script

Following is the script to copy all libraries of a certain command to make my chroot environment. For example: ./cplb.sh /bin/ls will copy all the libraries of ls command (i.e., the files listed by ...