Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

learn more… | top users | synonyms (2)

1
vote
1answer
461 views

How can I script xrandr's scale function to switch to the next or previous resolution in a predefined list?

xrandr has a nifty feature that lets you scale your entire screen so that your virtual resolution is larger or smaller than your actual resolution. I use it on my netbook's 1024x600 resolution screen ...
1
vote
1answer
6k views

C shell script : how do I compare two strings?

I'm a C shell user. I've two files. file 1: A B C D E file 2: A C B D E I want to compare only A-A, B-C, C-B, D-D, E-E using a for loop. If the strings match, then print "match". The output ...
5
votes
1answer
173 views

How do I hook into Tar with BASH?

Long Story Short I'm working with Tar archives that contain PNG images in base64 encoding. I would like to use BASH (or whatever else works) to hook into the extraction function of Tar to decode PNG ...
1
vote
1answer
658 views

Delete all jpg in a folder that are smaller than specific width/heigth [duplicate]

I have restored with photorec about 7.500 jpg's. I have moved them all in one folder. A big portion of them is thumbnails. But i can't just go on and delete lets say all of them that are smaller than ...
0
votes
2answers
412 views

Making md5sum understand file names with spaces

I need to use md5sum in Python by using pipe to calculate checksum for a bunch of .mp3 files... is there a command which ignore whitespaces in filenames on the command line of md5sum program? For ...
1
vote
1answer
376 views

while loop is running only once?

I am trying to make a clip out of video file by playing it only for certain interval. make_mclip.sh #!/bin/bash mediafile=$@ mediafile_fullpath=$PWD/./$mediafile tmpedlfile=$(mktemp) mplayer ...
0
votes
5answers
100 views

How can I modify variables

I have the following variable: col=1,3,4, Is there anyway to select the numbers within the variable: (i.e. 1 3 4 and work with them? Such as choosing the "1", "3", or "4" column from a .txt file? ...
0
votes
0answers
26 views

Variable Substitution in sed [duplicate]

I have this script and I need to count the lines inside a file, then pass the number of lines counted to a for loop so that I can get the contents of each line and put it in a variable. My question ...
-1
votes
1answer
241 views

Select a range of files from directory structure /year/month/date.db

I have databases stored in the directory structure year/month/date.db an example would be db/2013/10/15.db I need to be able to select a range of these with a script ("dbSelect ...
2
votes
3answers
701 views

How to put fixed-width, vertically-oriented key-value pairs in a CSV file?

I have a text file with the following type of content: OPERATION_CONTEXT VMD1HTE1A71_ns:.oc.GJ_OAD2 alarm_object 1130 On director: VMD1HTE1A71_ns:.temip.VMD1HTE1A71_director AT Fri 18 Oct 2013 ...
1
vote
1answer
156 views

What is the difference between ' and "? [duplicate]

I tried to create a text file in a bash script. The echo command spans multiple lines and has some double quotes "". #!/bin/bash echo "blabla bla bla bla "blabla" bla bla " bla bla bla" and so on ...
4
votes
2answers
338 views

Bash-script. Shift seconds

Maybe somebody can help me. In bash I don't know how to do that. I need to do a bash-script. At stdin I have .srt file of subtitles in this format: num HH:MM:SS,SSS --> HH:MM:SS,SSS text line 1 ...
6
votes
2answers
1k views

Detect if running in a virtual terminal?

I'd like to autologin to tty1 on login and then use vlock to lock it. How can I detect from Bash if the current terminal is a console virtual terminal (e.g. tty1), so that I can put the vlock line ...
2
votes
2answers
462 views

mv complains about standard input in a pipeline that filters file name with grep

I'm trying to move several .avi files that have spaces in from a CD to my home folder. I've already know how to get rid of the spaces: find /media/mathscd/ | grep -L -r "*.avi" | for file in *; do ...
3
votes
3answers
701 views

copying specific files in directory

I am trying to copy some of the files in a directory. The directory contains following files my current directory is ~/certificate/ drwxrwxr-x 2 ubuntu ubuntu 4096 Oct 16 11:58 apache -rw-rw-r-- ...
4
votes
1answer
276 views

returncode of command in a pipline [duplicate]

The following script runs on Solaris using /bin/ksh and on Linux using /bin/sh cmd | tee -a cmd.log | tail exit $? The output of cmd is saved in a file cmd.log and the last lines are displayed on ...
1
vote
1answer
356 views

Binary search for a failing line

git has bisect run to figure out which revision an error was introduced. I have a big file (100GB) and at least one of the lines is bad, but the program I have to check it with will not tell me which ...
2
votes
3answers
171 views

How can i get five seconds of data appended to the end of file?

suppose if a shell script appends a data to a file.txt like 1........... 2........... 3............. 4............. 5.............. Now i want another script that could check the fresh data ...
15
votes
5answers
40k views

Delete First line of a file

How can I delete the first line of a file and keep the changes? I tried this but it erases the whole content of the file. $sed 1d file.txt > file.txt
3
votes
1answer
101 views

Shell Script Size 57M

I have recently Downloaded yEd Graph Editor Installer shell script, which size is 57M When inspect that script head script root@home-pc:/usr/local/src# head yEd-3.11.1_32-bit_setup.sh #!/bin/sh ...
2
votes
2answers
115 views

Awk not rendering any result

My goal is to get the file created in the current month in a directory. It seems that the command is correct but not rendering any result: Date=`date '+%b'` echo $Date Oct ls -l | awk -v d="$Date" ...
2
votes
2answers
616 views

setting variables inside subshell when using <<

I am using the following method in order to pass commands into a subshell that is started by "newgrp". #!/bin/csh echo "Before newgrp" /usr/bin/newgrp users <<EONG echo "hello from within ...
2
votes
2answers
8k views

What is the meaning of $* in a shell script? [duplicate]

In a shell script file i saw "$*", what does it mean and when we have to use it?
2
votes
2answers
630 views

Script to delete text files

I was trying to make a script that searches for all ASCII text files in the directory that you point out and after that writes the path of every file to a text file. After that it's supposed to show ...
3
votes
4answers
2k views

Align text to center with padding on both sides

Is there an easy way to align text to the center with padding on both sides, with the column width being the longest line from the input? For example, this: aaa bbbb c ddddd ee will turn into this ...
3
votes
5answers
570 views

Delete all files in directories except those whose path are listed in a file

Given the following files: data/A/a.txt data/B/b.pdf ... date/P/whatever.log ... data/Z/z.jpg I would like to delete all files in the data/A/, data/B/, ..., data/Z/ directories except those files ...
1
vote
4answers
392 views

Reusing a variable

I was breaking my head for a day still not successful. I have this script: #!/bin/ksh fname=$1 for batchname in $(grep -i "Processing batch" $fname | cut -d "'" -f2) do Batch_state=`grep -c -i ...
1
vote
2answers
2k views

Printing fields using awk

< pool.sam awk ' /./ {printf $1} {printf $7+1,"\t"} {printf $3,"\t"} { if($2 !=16) {print "\t", "+";} else {print "\t","-";} {printf $4,"\t" ,length($10)+$4, "\t", "1"} }' I am ...
0
votes
2answers
92 views

Eval command in unix [closed]

Can someone convert this code? I got this from the web. I am new on this and don't know how eval works. Originally, there is a parameter from a command that is either a plus (+) sign or a minus (-) ...
3
votes
2answers
190 views

Running commands after event based outputs

there are commands like iwevent or tcpdump -n src host x.x.x.x that send to the stdout some lines when something happens. Is there any form of running some command inmmediatly after a ...
1
vote
0answers
139 views

Intercepting packets with bash

I'm wondering if it's possible to detect a packet that comes from certain IP and port(suppose IP 1.1.1.1 and port 80) and has some specific information on it (suppose "<h1>Web ...
4
votes
3answers
169 views

What is this complex line of code doing?

I am trying to understand this line from a shell script. I know that $(..) means run the .. and insert its output where you find $() in a statement. But what is going on between those parenthesis? ...
3
votes
2answers
460 views

What is the meaning of if [ -n “$(which voltdb 2> /dev/null)” ];?

I have very basic linux skills and now am trying to parse some shell scripts. I see this line in one of the scripts: if [ -n "$(which voltdb 2> /dev/null)" ]; I know that /dev/null is the bit ...
2
votes
1answer
359 views

Merging folders with practically the same name but different casing

When digging around in the advanced settings in Dropbox I lost a folder. I only discovered this about a month later. I managed to get this folder back from Dropbox however the file structure of the ...
1
vote
1answer
1k views

using find in Bash Script and checking if file is present

var= "$(find . -name 'gen*.bt2')" if [ "$var" == "" ] then echo bad else echo great fi I get errors ./script.sh: line 4: ./gen.4.bt2 ./gen.rev.1.bt2 ...
2
votes
1answer
130 views

Any better method than this for sorting files by their creation date?

I needed to display a list of directories sorted by their creation date and I came up with this code snippet that I thought was kind of clever. Is there a more obvious way to do this that I'm missing? ...
0
votes
2answers
88 views

Run level script - Help

I want the following command to be ran, as soon as system boots. glances -s -P redhat & How to achieve that? I tried writing a run level script which didn't work as expected.
0
votes
3answers
2k views

Script to login to ssh twice

I need to login through ssh twice with a script and can't get it to work. This is what I have in my script file: #!/usr/bin/expect set login "user" set addr "address1" set addr2 "address2" set pw ...
4
votes
2answers
586 views

How do I run a script when I switch between keyboard layouts

I use more than one keyboard layout, and I would like to find a way to run a script when I switch between them. Is this possible? So far, I can assign a shortcut for a script like this: #!/bin/bash ...
1
vote
3answers
322 views

splitting the string in bash script

I am new to bash script. I am taking some input from user and checking details about that. Example: $HOME/Documents/test/one.txt I take the above string as an input and want to retrieve one.txt, I ...
12
votes
0answers
356 views

Should I use $* or $@? [duplicate]

Which one of $* or $@ is better to use (in array syntax,command line parameters, etc.) to avoid any bugs/problems in code? Or it does not make any difference?
2
votes
1answer
762 views

What's the problem with this script to change wallpaper?

I'm very new to Linux's world, so I would ask to forgive me for every stupid or too simple thing I will ask now. I installed Elementary OS from their website just yesterday. I wanted to change my ...
3
votes
2answers
162 views

Sourcing a shell script from within Emacs

I would like to source a shell script that changes my environment variables from within Emacs. That is, I would like the shell script to change the environment in which Emacs runs, and I would like to ...
-1
votes
2answers
86 views

Make a new sniffer [closed]

How can use the Linux-kernel to supervise what is going on, about the new connections, new ports, connected hosts? Like I will do a new sniffer. Which files should I monitor to know what is going ...
2
votes
1answer
4k views

How to assign result of sed to variable

Below is a complete copy of a demo I'm using to to figure out to get the sed command to get rid of the spaces in a persons name, and compress it down to not have spaces. Once this is done, I want to ...
1
vote
1answer
103 views

What is the use of ; in a single line command?

What does ; mean in single line scripts like this: while true; do sudo -n true; sleep 60; kill -0 '$$' || exit; done 2>/dev/null & Does it mean new line, or "next command"?
5
votes
1answer
165 views

What is the difference in these two bash environments?

I notice that with bash scripts, some people use a different shebang to the one that I'm used to putting at the top of my own. Can someone simplify the difference between these two? I use the ...
2
votes
1answer
1k views

How to write a Shell Script using the condition from a database

Consider this is the condition I need to check select count(*) from nm.table1 where column1 =true; Now it should come out of the db (PostgreSQL) and use IF THEN ELSE LOOP in the Unix Something ...
2
votes
1answer
120 views

Why does backslash get converted to space in echo statement if IFS='\'?

Why is \ is converted to space on setting IFS='\' var="'(]\\{}\$\"" IFS='\' echo $var # '(] {}$"
11
votes
2answers
8k views

Regular expression in bash script

This is my first time bash scripting so I'm probably making an easy mistake. Basically, I'm trying to write a script that gets the groups of a user, and if they are in a certain group, it will log ...