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

learn more… | top users | synonyms (2)

2
votes
4answers
94 views

Flattening folder structure

I have this folder structure: ├── foo1 │   ├── bar1.txt │   └── bar2.txt ├── foo2 │   ├── bar3.txt │   └── bar4 with a space.txt └── foo3 └── qux1 ├── bar5.txt └── bar6.txt that ...
2
votes
2answers
44 views

How to print out every other line to the monitor

Have this tiny script down below and want to print out to the screen every other result. What are the ways of doing it? #!/bin/bash for ((n=5, j=1; j<=9;j++)) do echo "rez: $n*$j"=$((n*j)) done ...
1
vote
2answers
40 views

How to use process substitution within a case statement without getting syntax errors?

I have a script loaded as a service in /etc/init.d/myfile When I try to start the service I get the error /etc/init.d/myservice: 21: /etc/init.d/myservice: Syntax error: "(" unexpected The issue ...
2
votes
2answers
77 views

Why does my cronjob not execute my shell-script?

I have a crontab that creates a dump of my database every night: 20 3 * * * /path/to/dailydump.sh dailydump.sh contains: #!/bin/sh DATENAME=`date +%Y%m%d` ...
2
votes
2answers
66 views

Collect files from several different directories and put them in one place

I have a large amount of ebooks that are very disorganized. Some of them are alone in their own directories, some of them are corrupted, some of the directories are empty. How do I gather my ebooks ...
0
votes
1answer
70 views

Run a script that displays an X window from an udev rule

I found several questions on http://unix.stackexchange.com & on http://stackoverflow.com related to launch script by udev rules. But I can't find exact solution or certain answer for executing ...
0
votes
1answer
28 views

Prepending text read from a file on the top of another file [duplicate]

I want to add "void mainfunction()" on the top of a file. I am reading the actual name of the file from another file and the name of the main function from another file. I was using sed -i '1i void ...
2
votes
2answers
63 views

parse one field from an JSON array into bash array

I have a JSON output that contains a list of objects stored in a variable. (I may not be phrasing that right) [ { "item1": "value1", "item2": "value2", "sub items": [ { ...
3
votes
2answers
111 views

Select lines starting with specific numbers

I have to show the PID, PPID and STATUS of the procceses on the system, but only the ones which PID starts with numbers in the range 5-8. So i tried something like this... ps xao pid,ppid,s | grep ' ...
1
vote
2answers
41 views

Modifying part of a string in bash script

I have a file named variables.f90 , having many lines defining different variables, as follows :: integer::n_monomer=6800 real*8::rx=5.0d0 #... randomly integer and real numbers defined ...
1
vote
1answer
37 views

How does executing a file change the std input?

Imagine I have a script, which contains the goto command. The goto command will search in the std input for a line like this : jumpHere. But the std input is by default the terminal. It only makes ...
7
votes
2answers
865 views

Was there a '\0' at the end of every script?

I'm wondering how did you dertermine the end of a script/file? I'm especially interested for old Unix versions (like V6). Is there a '\0' after the last written character?
3
votes
2answers
63 views

terminal warn on close when opened within a script

First, the question: How can I warn the user that a script is running when the user clicks the close button and the terminal itself (and the process running in it) was started from the command line. ...
1
vote
1answer
68 views

awk in ssh in su in a command substitution

I am creating a script that will ssh to a host and print all the user accounts and when they will expire. On a host I can run awk -F':' '{ print $1}' /etc/passwd and it will give me a list of all ...
0
votes
1answer
73 views

create a user via script

I want to create a new user in a specific group when I issue the below command. sudo ./create_user.sh "test" "firstname lastname" The create_user.sh script looks as below. #!bin/bash #sudo ...
0
votes
1answer
48 views

Can't concat file paths, permission denied

I can't realize why if I just try to concat some file paths (without opening the files), I get "permission denied": #!/bin/bash if [ "$#" -eq 1 ]; then path1= "./src/$1" path2= ...
1
vote
2answers
65 views

How to make a filter more efficient

I've created a script to compare a list of users from a MSSQL database against a list of disabled AD users. The tool we use for AD authentication returns data in the following format (with plenty ...
1
vote
3answers
124 views

iterate over file and send lines as positional parameters to another file

I would like to iterate through a file containing dates (named dates.txt) in the following format: 2009 08 03 08 09 2009 08 03 09 10 2009 08 03 10 11 2009 08 03 11 12 2009 08 03 12 13 2009 08 03 13 ...
0
votes
0answers
31 views

open Mysql connection for long time to execute queries in block

I am writing one script which execute bunch of queries in block. here block means version number, each version have different different queries. I write two shell script. 1 version.sh version.sh ...
1
vote
3answers
120 views

Can I make [ $(($1 % $check)) -ne 0 ]; be more performant and not be killed?

If have the following code which works for up to 13 (line 2) in a few seconds but when I try and do upper teens and 20 it gets killed after a couple of minutes. divisible_by () { for ((check=2; ...
-2
votes
1answer
65 views

Why do I get “-eq: unary operator expected false”? [duplicate]

I get $ ./5_divisible_by_1_to_10.sh ./5_divisible_by_1_to_10.sh: line 16: [: -eq: unary operator expected false true for: divisible_by () { under_test=$1 from=2 to=4 divisible=0 for ...
2
votes
1answer
78 views

Avoid backslash expansion with echo in dash

First create a file with this exact content: a\nb I named this file foo, if I run the following, it prints the exact content of the file: bash -c 'bar=$(cat foo);echo "$bar"' But if you run it ...
4
votes
1answer
33 views

Simple problem, Long read: How to overwrite file residing on ESP at Linux boot

First, foundation. Here is my setup: I have a 64-bit dual-boot system running Windows 7 and Linux Mint 17 Cinnamon. I use rEFInd to graphically choose which system to boot. A little bit about ...
34
votes
2answers
4k views

Why is using && 75 times faster than if…fi and how to make code clearer

I have the following working code: largest_prime=1 for number_under_test in {1..100} do is_prime=true factors='' for ((divider = 2; divider < number_under_test-1; divider++)); do ...
1
vote
1answer
23 views

How to use passed-in parameters for shell script?

I know little about shell script but I want to try to implement some complicated scripts. Say I have a doitall.sh with the content like: zip -j version_a_en.zip en_filea1.txt en_fileb2.json And a ...
2
votes
1answer
48 views

How to use variables in sed command

I'm trying to run sed -i "/$variable/c \$variable1' file.txt But it's not displaying any change in the file: file.txt. But the same command, with out the variables works fine: sed -i "/variable/c ...
2
votes
1answer
113 views

Merge some tab-delimited files

I have 100 files with 57,816 rows each.I want to do an outer join of these files by merging on basis of the common column. I am using R programming for this but this is very slow. fileList <- ...
2
votes
3answers
77 views

How can I run Linux shell scripts which needs root privilege from a web page

I'm trying to run a linux shell script which requires root privilege via Apache, Is there any way to run scripts which needs root privilege, rather than setting suid and sudo privilege to Apache. ...
0
votes
1answer
39 views

For loop brackets - C like syntax

When i am using the below syntax to iterate why two brackets are needed ? for (( expr1; expr2; expr3 )) do command1 command2 .. done and the below code doesn't work ? and throws error "syntax ...
1
vote
1answer
42 views

Unix scripting - for do command with & [duplicate]

I am trying to use a for do command that I can run as a one liner in Solaris/Linux, and would like the do command to run asynchronously. I have tried the following: for i in `ls AMQ*.FMT`; do ...
-3
votes
2answers
72 views

Building tree diagram [closed]

Suppose I have a program P11 in a directory; it calls 2 other programs P21 & P22. Each of P21 & P22 call 2-2 other programs. i.e. Level-1: |--------------P11-------------| Level-2: ...
2
votes
1answer
125 views

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

Script: text="//ABC/REC/TLC/SC-prod/1f9/20/00000000957481f9-08d035805a5c94bf" echo ${text##*/} Here, what is the meaning of 2nd line in the above 2 line script?
0
votes
2answers
52 views

Combining two bash script and using a menu

I have two scripts, one that is used on a folder with csv files and another on a folder with .tar.gz files. In the second script, I first unzip the files before doing anything with them. Now I want to ...
0
votes
1answer
63 views

linux/shell command to control screen brightness in android

I am working on a kiosk project using an android tablet.If there is no input power to the kiosk for a long time then, the tablet will eventually shutdown.In order to auto-reboot the tab when the power ...
2
votes
3answers
46 views

Email using shell script using email address from external flat file

I'm using alexkowalski script from Email using shell script MAILADDR=(mail1@example.com, mail2@example.com, mail3@example.com) for i in "${MAILADDR[@]}" do echo "Mail test..." | mail -s ...
0
votes
1answer
35 views

A small script about wget

I want to download an image file called mch_aktuell_gross_20141229_79514688.gif (basically a forecast gif) from www.meteoradar.ch Here is my script: #!/bin/bash wget \ --recursive \ ...
5
votes
1answer
123 views

echo colored text which changes colors dynamically

Is there any way that i can print a colored text on console which keeps on changing its colors dynamically(with or without a specified time interval) just like some greeting cards in which the ...
2
votes
2answers
57 views

Find file, check size and overwrite when filesize is different

Today I found a little bug in my own written CMS. Now I want to rewrite all the files on the server with the same filename. However, I do have some customers with the specific file customized so I ...
6
votes
2answers
357 views

Move file but only if it's closed

I want to move large file created by external process as soon as it's closed. Is this test command correct? if lsof "/file/name" then # file is open, don't touch it! else if [ 1 -eq ...
2
votes
2answers
97 views

Create arrays with brace expansion in loop

I would like to generate a number of arrays that differ only by year. In the loop, I create the arrays with brace expansion and a variable. I tried the following code without success: ...
0
votes
1answer
64 views

need help with a a symlink and the PATH variable

I tried to install drush with composer from a script that is runing with sudo $nameofuser `logname` #drush installation getcomposer(){ # Composer Global installation curl -sS ...
2
votes
0answers
33 views

Generate array of strings combined with number

I would like to generate a local array in a shell/bash script that consists of the following elements: JF-1998, JF-1999, JF-2000,... , JF-2011. That is, a string JF- combined with the years from 1998 ...
1
vote
1answer
38 views

How to check the file type in a script

I want to do a loop for all the images in a directory. The images doesn't have extension so I have to read the first bytes of the image to know its type. The loop should end up being something like. ...
3
votes
0answers
37 views

Rename file with the name from a variable [duplicate]

I want to rename an image with the text in that image. For that I use an OCR and I try to store the name in a variable and use that variable in the mv command but I get mv: target ‘file’ is not a ...
3
votes
2answers
69 views

Append unix timestamp to files with space using a script

This script works fine for all files recursively as well but it does not name files that has space in between. For example it throws error for the files "this is a test.txt" or "test file.txt" Any ...
0
votes
1answer
25 views

how to export nam of logged in user correctly?

I have the following script here. #!/bin/bash #some initial variables DLURL=https://raw.github.com/horvan/drubuntu/master DIRURL=/opt/.drubuntu #Get files to run the installation wget -O ...
4
votes
5answers
249 views

What command(s) will feed a tab-delimited text file and cut each line to 80 characters?

I've got multiple-line text files of (sometimes) tab-delimited data. I'd like to output the file so I can glance over it - so I'd like to only see the first 80 characters of each line (I designed the ...
2
votes
2answers
58 views

Use config file for my shell script

I need to create a config file for my own script: here an example: script: #!/bin/bash source /home/myuser/test/config echo "Name=$nam" >&2 echo "Surname=$sur" >&2 Content of ...
1
vote
2answers
49 views

Creating a list of files, removing “duplicates” with different suffix

I have a problem that (I think) require a bit of script-magic - not sure what would be best though... I have one directory with lots pictures in different formats - jpg, gif, png, tiff and svg. Some ...
1
vote
3answers
51 views

cd works in shell but not in script [duplicate]

I frequently have to cd from $HOME to a particular long directory path. So I thought I'd put a cdscript in $HOME to make getting there a little quicker. cdscript: #!/bin/sh directory="/some/big/long ...