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

learn more… | top users | synonyms (2)

1
vote
2answers
44 views

Detect and remove empty directories from list

A common problem game developers have with the Unity3D engine and Git is that Unity and Git fight for whether an empty directory should exist or not - Git doesn't care, Unity3D will keep making git ...
0
votes
1answer
43 views

Need help parsing a filename and adding it to a text file

I have a directory full of files with the date they were created in the filename (ie "mvr-20160420.csv"). The files contain comma delimited data that I'm combining into a single text file. I'm ...
0
votes
2answers
36 views

Shell script for executing programs within a loop and checking their exit values

How do I do this in a shell script: for (int i=0;i<1000;i++) { run applicationA run applicationB if (retvalFromApplicationB!=0) {continue;} else {pipe ouptut (stdout) from ...
-1
votes
2answers
49 views

shell script replace and add next line with special characters [closed]

I am trying replace a line with another line and add new line below that using a shell script. I want to replace: export PATH with: JAVA_HOME=/usr/lib/jvm/java-1.8.0-ibm-1.8.0.2.10-1jpp.1.el7....
0
votes
1answer
59 views

associative array with two strings

is it possible to loop a simple array with key and value with a string in the [key] part ? #!/bin/bash -x wget url://stringlist1 wget url://stringlist2 #cat/sed some stuff .... declare -A ...
1
vote
1answer
48 views

Rewrite a find command that uses sed -i for AIX

I have a script that searches for a string and replaces it via the sed command. If that string contains special characters, the script will escape them (except for the slash because it's my current ...
2
votes
2answers
144 views

pssh (Parallel-ssh) passing different parameter for every host

I have a file called hosts which looks as follow: host1 host2 host3 host4 ..... On these machines there is also a local user named as the machine name. host1 user is created on host1 host and so ...
1
vote
1answer
39 views

How to add an word for a line where transpose has done

I have a file fruits: apple grapes banana orange By using cat < fruits | tr "\n" "," It will give output as apple,grapes,banana,orange, Here I want to print the file name also along with ...
-7
votes
1answer
55 views

help with a bash shell script that creates directories

I have a problem I been trying to tackle. If anyone can help, it would save me a headache! For reference,I started self learning so I'll be looking for problems around but can't find the answer for ...
2
votes
2answers
88 views

bash read of a newline, printf reports character 0

I use bash printf function to print ASCII codes of characters in an input file, but for some reason printf outputs ascii code 0 for LF characters, instead of 10. Any ideas why? while IFS= read -r -n1 ...
0
votes
1answer
68 views

Reading user input with read back

when I use simple bash command #!/bin/bash echo Please, enter your name read NAME echo "Hi $NAME!" and run it using source filename.sh it gives me an error :Undefined variable what could be the ...
0
votes
2answers
39 views

Universal abstraction of ls

Specs OS: OS X; Client: Terminal; Shells: sh, bash Problem I'm writing a shell script that adds a layer of abstraction to the ls command. I want to make it "unbreakable", so I started by figuring ...
2
votes
2answers
47 views

Using awk to combine two csv files on three fields too create a new csv file

I would like to compare fields in 2 csv file and create new csv file for output. I have 2 csv files; this first file is PCs in my network: 192.68.205.76,189,FC3F.DB02.ED78,2ndfloor-c001a-asw1,...
2
votes
1answer
112 views

Multi processing / Multi threading in BASH

I have a test file that looks like this 5002 2014-11-24 12:59:37.112 2014-11-24 12:59:37.112 0.000 UDP ...... 23.234.22.106 48104 101 0 0 8.8.8.8 53 68.0 1.0 1 0.0 0 68 0 48 Each line contains a ...
1
vote
2answers
51 views

Bash find and replace in a C++ file

I have a C++ script for which I would like to change variable values in some places and then compile, doing this many times for a set of numbers. The following shows my shell script: #!/bin/bash ...
6
votes
1answer
152 views

Map ordinal to alphabet in shell script

I'm quite new to shell scripting. Is there any simple solution to map ordinal number like 1, 2, 3, ... to alphabet a, b, c in shell script? Thanks!
1
vote
1answer
32 views

Save number of lines output to a variable in a shell script without consuming the output

I have a shell script where I have a if statement based off of the number output lines output from another call. (In my case do something there is more that 1 line of output). LINES=$(function_call | ...
3
votes
3answers
383 views

Using grep with a pattern that contains a variable to be expanded

I have a file on the form 2e95d7582c53583fa8afb54e0fe7a2597c92cbba 1461065389 52880 temp/hello/file.txt 46c897a7aa8a641f46080b3431860bd0cd4a8f05 1461066221 207 temp/Another file.txt ...
2
votes
3answers
61 views

How do I find my distro name via the command line?

Is there any command that outputs your distro name like this: CentOS Ubuntu,etc.? I am looking to make a script that will execute a different batch of commands for each distro and I need to know how ...
0
votes
0answers
20 views

Printing specific column in bash script and avoiding duplicates [duplicate]

I am writing a Bash script to print a specific column from a file. But that column contains many same strings and I want to just print every content just once. I tried this - awk '!seen{print $9}' $...
0
votes
0answers
30 views

How do i run multiple scripts within another script in the same directory?

Last part of a project and I've created 3 scripts already that do the following, but I now need to run them within a 4th script as if it was one program. Below are the instructions as well as the code ...
2
votes
2answers
149 views

bash source script.sh with exit 0

I use a lot of external files in my scripts. But I have a problem, that if I source a file with exit in the contents of the file, the script exits from loading and the strings that I want to use are ...
2
votes
4answers
575 views

print specific line from multiple files

I have a collection of 5000+ files and I just want to create a output.txt file which contain 27th line of all file along with filename. well I am noob at linux level so what i got from internet is to ...
3
votes
2answers
67 views

use printf to format output of an array

I have an array that contains details about each NIC. Each array index consists of three space-separated values. I would like to have a nice table as output. Is there a way to assign formatting ...
3
votes
1answer
263 views

curl outfile variable not working in bash script

Attempting to shorten a bash script that uses curl to fetch multiple API calls takes something like this: curl --user $USER:$PASS https://api.example.com/foo -o 'foo.json' curl --user $USER:$PASS ...
0
votes
2answers
136 views

How to copy files from directory meeting certain criteria

I'm trying to copy files from directory A to directory B. But I want to copy only files that have lower size then X and don't have file extensions specified in file extension.txt. My main problem ...
0
votes
1answer
50 views

How do I count the number of files in all subdirectories and add the counts together

I am trying to count the number of file in each directory/subdirectory, add them together and get a total which I can then compare to another directory: #!/bin/bash echo "Checking directories for ...
0
votes
1answer
28 views

What are the unreadable characters in Linux Anaconda install script?

The Anaconda for Linux installation scripts contain about 750 lines of a pretty straightforward set of bash commands, but they are then followed with 1.4 million lines of characters unreadable (at ...
2
votes
2answers
51 views

What's the difference between 'test' and evaluating with /dev/null?

I noticed different .sh scripts for homebrew which check whether it's installed. One uses this syntax: if test ! $(which brew); then The other uses this syntax: if ! which brew > /dev/null; ...
1
vote
1answer
146 views

Prevent shutdown using shell script run at shutdown

Background: I have a Python script that runs (infinitely) from startup in the background of a Ubuntu server. The process is ended by sending a SIGINT which is handled by the script which finishes all ...
3
votes
4answers
198 views

Check if a shell variable has more than one line using built-ins?

I can do this by calling the external utility sed (for a known non-empty $myvar) like so: if [ "$(printf %s "$myvar" | sed -n '$=')" -eq 1 ]; then echo "Your variable has only one line, proceeding" ...
0
votes
0answers
45 views

netcat output does not write to array if launched from cron

I am able to run this script as a user or root with bash or sh. Doing so gives me the output that I expect (arrayFWS is written to file, then emailed). However, when I run it with crontab with user or ...
0
votes
0answers
13 views

Declaring multiple arrays from contents in multiple directories, then iterating over those arrays and their contents [duplicate]

In a bash script, I'm trying to declare 15 separate arrays with the contents of a folder for 15 separate folders (IE; array1 = contents of folder1, array2 = contents of folder 2, ..., array15 = ...
1
vote
0answers
50 views

Bash scripts not found. Maybe EOL issue? [closed]

I am facing a problem that is driving me crazy. In the past months I have been developing a project based on a Linux distribution (Openwrt) that has been recently updated. My project has a lot of bash ...
0
votes
1answer
63 views

How do I calculate the column percentage of a file?

I have a tsv file that contains some values. I want the sum of each column and total number of values and percentage values. Eg: file.tsv contains x 1 1 0 1 x x 1 x ...
6
votes
2answers
323 views

Sed with inplace editing changes group ownership of file

I have shell (php) script that gets in touch with target file this way: inspects whether file and directory are writable with php 's is_writable() (I don't think that this is problem) does in-place ...
1
vote
1answer
78 views

Check if the files in a specific directory have the proper extension?

I have created a script that will create a few directories and then organize other files from one directory by moving them into specific sub-directories based on their extension (i.e. .gif in media, ....
0
votes
1answer
27 views

assign string components into variables [duplicate]

Looking for a smarter way to do something I'm doing already. I have a string: "firstbit.secondbit.thirdbit.fourthbit.fifthbit.sixthbit" The content between the periods changes, but the delimited ...
1
vote
2answers
96 views

bash - All possible combinations of words from different files

I have n files with one word per line file 1 file 2 file 3 ... 1_a 2_a 3_a 1_b 2_b 3_b 1_c 3_c I want to write a bash script that takes all this files ...
1
vote
1answer
51 views

bash set -o errexit problem or the way of incrementing variable?

I have a shell script incrementing a variable like in the example below with set -e: $ var=0; echo $? 0 $ ((var++)); echo $? 1 $ ((var++)); echo $? 0 $ ((var++)); echo $? 0 $ echo $var; echo $? 3 0 $ ...
1
vote
1answer
609 views

How to execute shell script on Kali Linux startup?

I need to execute a shell script on a Kali Linux startup. I am using 2016.1 version of Kali Linux. i tried many things like rc.local, init.d, X11 and GDM3 config etc. but I couldn't get it work. ...
0
votes
2answers
56 views

Get the latest value of an environment variable is a bash shell script

I wonder how can we get the latest value of an environment variable in a bash shell script. Problem I am having is, I have a environment variable which can be changed externally multiple times. But ...
1
vote
1answer
346 views

Automatically enter SSH password without using SSH Key, 'expect', 'sshpass' or Python

I have small device that starts up a tiny VM of PowerPC linux that I need to SSH into from a script on a tiny version of Yocto linux. The PowerPC VM SSH passwords stay the same, but it resets most of ...
0
votes
3answers
53 views

`tcsh` repeat with subshell

I'm trying to figure out how to repeat a complex command inside a repeat in tcsh, like so repeat 9999 (curl http://localhost:80/index.php; echo) I am using a subshell here instead of { and } ...
1
vote
1answer
56 views

List hidden files only (not just dot files) using an ls alias

I would like to use an ls alias (like l.) to output a colored list, consisting of only hidden files & directories, whether or not they begin with a dot. Any suggestions? Example of desired ...
0
votes
2answers
39 views

Sed incremental arithmetic

I want to replace a number at the end of a string by incrementing the number by one each time I run a specific sed line. the string looks like this: server-port=25555 I was thinking I could run ...
1
vote
2answers
75 views

Read files from directory and organize them by extentsion into corresponding folders

I'm trying to create a bash function script that will allow me to create multiple directories with the names below. I'm also trying to organize files by extension into their corresponding folders (i.e....
0
votes
0answers
12 views

runuser error handling

We use runuser inside some of our deployment scripts. In looking at the scripts I'm wondering how the error handling would work if any of the commands within the runuser steps errors out. In ...
0
votes
0answers
22 views

Automated port change

I want to Create a Bash file that a user can execute to change the port a service runs on. Essentially all I have to do is replace a number in a line of text with another number generated by a list. ...
0
votes
1answer
27 views

Filter for remote server response from netcat SMTP scan

I am using netcat to test if remote exchange server (lets call it exchange1) is online with this code. nc -w 3 192.168.130.17 25 I want to create a file that has that servers name if and only if ...