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

learn more… | top users | synonyms (1)

2
votes
3answers
84 views

What is the language that appears on the first line of a script? [duplicate]

Bash scripts start with the following line #!/bin/bash # Rest of script below ... In bash the # character is the start of a comment, but #!/bin/bash is definitely not a comment, therefore it isn't ...
3
votes
2answers
120 views

How to make /etc/init.d script act like it's launched under X?

I'm trying to track down some quirkiness with a Java application that misbehaves when launched via a startup script in /etc/init.d , but runs fine when you open a GUI terminal window and run it ...
2
votes
1answer
178 views

Linux nuisance: /dev/stdin doesn't work with sockets

Linux has this blitheringly annoying peculiarity that /dev/stdin won't work with sockets - it is hardcoded to return ENXIO. Try this: socat TCP-OPEN:localhost:1234 EXEC:cat\ /dev/stdin,nofork ...
4
votes
3answers
350 views

How do I create a bash script that sums any number of command line arguments?

How would I create a bash script that the user can use to sum any amount of command line arguments? For example, say my script is called sum: sum 3 3 sum 3 5 8 sum 9 8 21 38 And so on.. I ...
4
votes
3answers
177 views

How to start a script with clean environment?

I tried the following but it doesn't seem to work: $ cat script.sh #!/bin/env -i /bin/sh /bin/env $ script.sh /bin/env: invalid option -- ' ' Try `/bin/env --help' for more information.
1
vote
3answers
199 views

compare files line by line and create new one bash programming

I have two text files. File 2 has logs over 1,000,000. File 1 has IP addresses line by line. I want to read file 2 lines and search these lines in file 1, I mean: file 1: 34.123.21.32 45.231.43.21 ...
3
votes
4answers
200 views

Does cron jobs per se represent a significant burden on a modern system?

I'd like to run a pretty simple script (is there a dir with name x in dir y if so move it to dir z–and x will only be there about once a day) every 15 seconds or so (one minute divided into 4*15 ...
3
votes
1answer
150 views

echo $? returning 0 instead of 1

[root@server ~]# bash << eof > cat adsfasdf > echo $? > eof cat: adsfasdf: No such file or directory 0 Could anyone please explain why it is returning exit status 0 instead of 1?
1
vote
2answers
175 views

run a script at shutdown in Debain

I am using Debain wheezy. My problem is , I am using a limited 2.5 GB net connection. My idea is simply running a script as #!/bin/bash date >> ~/mydatausage.txt ifconfig -a >> ...
1
vote
1answer
75 views

Find a particular nesting of directory names, e.g. …/project/dir1/dir2

I'm having some issues dealing with the find command; I don't know the syntax for it very well and I need to use it in a script to find a specific directory structure that could be located anywhere. ...
1
vote
1answer
150 views

Run an executable with a Shell Script

I have mplayer installed and I want to create a simple shell script that runs in bash and executes mplayer * in the current directory. So, how to call upon mplayer in the shell script? I am a newbie ...
3
votes
1answer
79 views

Bash capture any error like -e but don't exit, do something else

I want to set a flag in a shell script (bash) so that if anything returns non-zero, a flag is set (i.e. set a variable like errors="True"). So far, I've thought of calling the script with ...
1
vote
1answer
144 views

Exiting a Bash script when a sudo child quits

I'm trying to launch a couple of sub-programs from a bash script and then wait on either of them to quit before quitting the other and exiting the script. CMD1PID= CMD2PID= exit_trap () { ...
2
votes
2answers
68 views

scripted pdf code review

What I try to achieve I need to review a bunch of C source code spread out into dozen of directories. I already have a bash script which does the following: It searches for all source codes in the ...
0
votes
2answers
727 views

Convert Month Number to Month Name

is there a way to convert month number to name? example: 2013-10-22 will become Oct 22 I don't have the GNU date and my OS is AIX.
-1
votes
1answer
123 views

Copying records into another file based on condition

I have a file that has multiple records. I have to copy those records that have a code '06' at a specific position, lets say, at position 19 and 20, into a another file. Records don't have any spaces ...
1
vote
0answers
31 views

Shell Script to search for pattern and sending the mail [duplicate]

I want to generate the shellscript. In this i have to search the pattern from the log file which is in another directory and mail if the pattern was found and mail to other address if the pattern was ...
0
votes
1answer
46 views

Shell script to send a mail once every 20 days [duplicate]

Need a shell script to be called via cron job every day and see if it's 20th day,it should send a mail
-3
votes
2answers
247 views

Need a shell script which should send a mail to me once every 20 days

Can some one tell me the logic or the entire script to create a shell script to send a mail to me once every 20 days
0
votes
3answers
448 views

How do you create and execute a bash script which calls an executable from higher folder?

I'm attempting to write a very simple script which calls an executable from a higher level folder. If I were just typing the command into the console, I would type ../filenamehere {options} ...
2
votes
1answer
99 views

shell script to append ID for newusers command

I am in the process of creating 60 users locally in a linux machine. I wanted to do it automatically and so I found I can use the newusers command to add the users in batch. I have the users and ...
0
votes
0answers
329 views

LFTP mirror upload only non existing files to remote directory

Every 5 minutes some new files are downloaded via lftp to a local directory. I need to upload to another ftp only the non existing files. My script so far is: #! /bin/bash today=$(date +%Y%m%d) ...
3
votes
1answer
174 views

Array Cartesian product in bash

Is there a way to generate cartesian product of arrays without using loops in bash? One can use curly brackets to do a similar thing: echo {a,b,c}+{1,2,3} a+1 a+2 a+3 b+1 b+2 b+3 c+1 c+2 c+3 but I ...
1
vote
2answers
92 views

Meaning of the following linux commands

cat "$1" > /tmp/file.$$ 2>/tmp/file0.$$ grep "*" /tmp/file.$$ >/tmp/file0.$$ I understood that in the cat command, if an error occurs, the error will be shown in file0.$$ and if it ...
3
votes
2answers
185 views

How to find frequency of occurrences of strings contained in a file?

I have a file that contains a list of URLs of the form EDIT http://www.google.com/absd/siidfs/kfd837382$%^$&, www.google.com, google.com yahoo.com/list/page/jhfjkshdjf... I ...
0
votes
2answers
61 views

need help in making script [duplicate]

I want to automate one task in UNIX and make one script. There is directory in which everyday 2 files comes and that files come anytime in between 10 pm to 1 am. file name is ...
3
votes
1answer
59 views

Using Bash to write to a device in /sys?

I have one of these: Basically, it's a USB device with three LEDs (red, green, and blue). The Linux kernel has supported this device through the usbled module for quite some time now. However, I ...
3
votes
1answer
141 views

Script to find the default Desktop Environment?

Assume a Linux Desktop Environment system is installed. When powered on and credentials entered, whatever Desktop Environment is started i would consider the default Desktop Environment. The user may ...
9
votes
2answers
265 views

Are quotes needed for local variable assignment?

Can I safely omit quotes on the right side of a local assignment? function foo { local myvar=${bar} stuff() } I'm mainly interested in bash, but any info on corner cases in other shells are ...
1
vote
2answers
119 views

Use of find in unix on strange file/directory names

Im a beginner scripter, writing scripts in tcsh and csh (these are taught in my course). I'm writing a script which uses find for putting path of directories this is the part of the script: set list ...
4
votes
3answers
381 views

using sed to replace pattern with hash values

I want to search the file and replace specific pattern with its hash (SHA1) values. For example, let file.txt has the following content: one S56G one two three four five V67X six and I want to ...
4
votes
1answer
69 views

IFS null is not the same as unset IFS?

I read a great question on here called Understanding IFS. I was surprised because the answers and comments quote POSIX which states that IFS= is not the same as unsetting IFS. If you unset IFS, ...
0
votes
4answers
187 views

A shell script that never dies

I want to write a shell script that never dies i.e, Shell script will repeatedly check whether Database is alive or not for every five seconds. The problem is At times the shell script stops ...
0
votes
2answers
76 views

Shell script to find what package provides a file on OpenBSD

# for i in `pkg_info -q`; do pkg_info -L "$i" | grep ^/ | sed "s/^/$i/g" | perl -pe 's/\//\t\//'; done | grep tasklist.desktop xfce4-panel-4.10.0p2 ...
2
votes
3answers
95 views

Syntax error in shell script

I have this script to divide a file over a 100000 or even more in 50000 lines. desc() { echo ...
2
votes
4answers
863 views

How to catch an error in a linux bash script?

I made the following script: # !/bin/bash # OUTPUT-COLORING red='\e[0;31m' green='\e[0;32m' NC='\e[0m' # No Color # FUNCTIONS # directoryExists - Does the directory exist? function directoryExists ...
23
votes
9answers
863 views

for vs find in Bash

When looping through files there are two ways: 1. use a for-loop for f in *; do echo "$f" done 2. use find find * -prune | while read f; do echo "$f" done Assuming these two loops will ...
0
votes
2answers
165 views

how to run .dump command in linux? [closed]

I want to create dump file of sqlite database from java but I can't run the below command from linux. I got the help of windows and I tried with linux but it appears one terminal nothing more than ...
1
vote
1answer
194 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
603 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 ...
4
votes
1answer
118 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
156 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
164 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
147 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
79 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
25 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
94 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 ...
3
votes
3answers
283 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
123 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 ...
3
votes
2answers
162 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 ...