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

learn more… | top users | synonyms (2)

-2
votes
2answers
78 views

How do you remove newline character in the middle of file?

File structure: Col1|Col2|Col3|Col4 123|456|abcdefg Tel.: 689346589934, xyz lckhasfkl|abc I want to remove the newline character from 'col3' only.Please suggest
3
votes
3answers
65 views

while read line in shell script - how to stop the loop?

I read a tutorial here that I can use while read line do wget -x "http://someurl.com/${line}.pdf" -o ${line}.pdf done < inputfile However this script keeps running with $line not containing ...
1
vote
3answers
73 views

Add line to configuration file from a bash script?

I am trying to figure out to locate a line in a configuration file, then to drop down two lines then to insert a line of code. I was attempting to do this in awk/sed but got stuck on the carriage ...
1
vote
2answers
53 views

How to use single quotes inside ssh and sqlplus

Below script helps me to ssh and do sqlplus to fetch info from database. I checked and it worked well but the only problem is if i use single quotes in the sql query then I am getting an error since I ...
0
votes
0answers
33 views

Fetch data from a CSV file based on multiple conditions

I'm trying a write a generic shell script which should extract data from a CSV file based on multiple conditions (generic) and write it to another CSV file. Sample CSV file: ...
8
votes
4answers
176 views

dirname and basename vs parameter expansion

Is there any objective reason to prefer one form to the other? Performance, reliability, portability? filename=/some/long/path/to/a_file parentdir_v1="${filename%/*}" parentdir_v2="$(dirname ...
13
votes
1answer
342 views

Where are bash line continuations after && and || documented?

I have seen this construct in scripts a lot and used it myself, but it bothers me that I can't seem to find it in the documentation. Example: [ -f file1 ] && [ -f file2 ] && echo ...
0
votes
0answers
31 views

Startup Profile Not Running From Bash Script, Only Manually

I'm creating a bash script to deploy CA ITCM (for Mac OSX) and upon completion of the install there is a command that can be ran to start all the services so that a reboot is not required. The command ...
3
votes
1answer
27 views

How to detect the architecture of the chroot from inside the chroot?

Let's say for example the host system is running Debian amd64. And on that system, another Debian i386 has been installed inside a folder using debootstrap. Then assume a shell script is running ...
1
vote
3answers
53 views

Find Directory if Number of files is over X

Am wondering if someone can advise on the best way to do this. In my Web Dir is around 100 folders; each folder is a clientID. Within each ClientID folder is a Sub-Set of folders. In each subset ...
2
votes
1answer
35 views

Inline debug (xtrace) in scripts

Is there a way to force enable or disable debug (xtrace) per command line in scripts ? In Windows Shell ("ms-dos") is an "@" which can prefix a command line, disabling that line to be showed if the ...
1
vote
1answer
28 views

How to have netcat server close after n seconds

I need to use nc in a weird way, where I want the server to first send a file, and then recieve a file, and this repeats. I would like to have every instance of the server server close after some ...
0
votes
3answers
64 views

How to display size “human-readable” in lsof | grep /var* [duplicate]

I am currently trying to see , all the files which are using /var mount. With lsof | grep /var* when Its displaying size in bytes. How can I display file size in MB. Thank you.
2
votes
2answers
53 views

SOLVED: Shell Script cant run man command

I have a script that runs commands & takes a screen shot. I want the man file to display & grab a screen shot of it. My script works for the commands alone but if I add "man " before the ...
0
votes
0answers
27 views

Tmux displays “<xzy not ready>” in the status bar

I'm using iTerm 2 nightly and I have the following tmux config setting for the left status bar: set -g status-left "#[fg=green]#h @ #[fg=cyan]#(extip | awk '{print \"ip \" $1}') ...
1
vote
1answer
45 views

Setting env variable through script on current session

Is there a possible way of setting env variable through script on current session. I have tried source option. But this works on the shell not through script. here is my script content source ...
1
vote
1answer
48 views

substitute from beginning of line with 1 of multiple patterns to the end of another line with 2nd pattern

I have a file like this: data data data $globaltext blah gibberjabber somemorestuff etc ); data data data $otherjunk yada gibberish etc etc more etc ); My desired result is this file: data data ...
3
votes
7answers
165 views

How to insert a string in array with different manner

I have a string like below. str='014387650' Now i want to split this string like below and put the value in the array. A[0]=0 A[1]=01 A[2]=014 A[3]=0143 A[4]=01438 A[5]=014387 ...
0
votes
1answer
27 views

How to run command after entering postgres

I am trying to execute ls after opening a new Guake tab and logging into postgres. guake -n guake -e 'sudo -i -u postgres && ls' The command successful opens a new tab then prompts me for ...
5
votes
1answer
236 views

Why does commenting out this line in a shell script (using pdftk) cause problems?

Consider the following simple shell script (using pdftk): #!/bin/sh echo "" | ps2pdf -sPAPERSIZE=a4 - blank.pdf pdftk \ A=blank.pdf \ B=blank.pdf \ C=blank.pdf \ cat A C \ ...
0
votes
0answers
68 views

!-2 not found when using alias [duplicate]

I'm lazy, so I like to make a LOT of aliases for some of my most common shell commands. I use the command sudo !! quite a bit to tack on sudo for root access, but when I use the following in my ...
1
vote
2answers
43 views

Bash - non-numeral arguments to [] operator(array)

I have a small script below; however, I don't quite understand the for loop and if statement. First, let's take a look at script: listFieldNumbers () { for ii in ${!field_number[@]}; do if [ $ii ...
2
votes
2answers
61 views

Is it possible to show rsync output on a single line?

I have a bash script that is rsyncing a large directory and the --progress function is great, but is it possible to show all this output on a single line? ie. as the files transfer, just spit it the ...
1
vote
0answers
14 views

Autoloading a particular driver, based on a detected specific kernel

I need some help in writing a tiny script and determining its placement within Debian 7.9 filesystem. As the title says, the script needs to be executed automatically on startup and, after checking ...
0
votes
0answers
20 views

How do I execute a command if a drive is not mounted?

I am trying to create a shell script to mount a LUKS volume if it is not already mounted. The LUKS password will be in the shell script. The shell script is being stored in a encrypted folder so it is ...
2
votes
1answer
127 views

bash while/read loop behaves differently in a mips/musl/busybox based VM

On a musl/busybox based system running in qemu (mips), the script #!/usr/bin/bash printf '%s\n' "${BASH_VERSION}" > test.txt echo 'test.txt:' cat test.txt echo "No process substitution:" while ...
3
votes
1answer
60 views

Bash append to file, removed during execution. Can this be fixed?

I just realised something rather stupid (my side) happened. I am currently running multiple programs on several machines while appending their output. E.g. machine01 is running "./calc 1 >> ...
-2
votes
1answer
27 views

How to pass arguments of the shell script when calling it?

#!/bin/bash ./bbmap.sh ref=ref.fa # creating index file from the input for $i in {ls*.fastq} # trying to run batch processing do ./bbmap.sh in=$i out={.} done It says: BBMap version 35.74 ...
1
vote
1answer
38 views

Find oldest directory name on a remote server?

I'm writing a backup script of sorts. My backup server contains 3 directories (named by date in the MM-DD-YYYY format) For example: 12-22-2015 12-28-2015 12-29-2015 Im writing my backup script ...
0
votes
2answers
119 views

Why does the parameter $0 give me only the basename instead of full path after converting x-shellscript to x-executable?

My problem here is that the parameter $0 gives the same result as ${0##*/}, and that happens after converting the x-shellscript to x-executable using the SHC program! OS: Debiab-8.2-jessie SHC ...
1
vote
1answer
22 views

mpack description (-d) from a script variable

In my script I have a variable named $message. I want to send this message together with a jpeg using mpack. One way that works: echo "$message" > myText mpack -s "test mail" -d myText ...
5
votes
5answers
262 views

Rename files based on their parent directory using find/xargs command?

I have a directory structure like this: Project/ | +--Part1/ | | | +--audio.mp3 | +--Part2/ | | | +--audio.mp3 | +--Part3/ | | | +--audio.mp3 ... I want to ...
0
votes
1answer
51 views

modify all of the files to read something other they what they do

the Objective is to write a proccess that literates through a tree then change the names of everything within that tree including the names of the tree itself (the leafs, the branches, and trunk of ...
2
votes
2answers
112 views

What is the difference between kill , pkill and killall

I am familiar with kill command , and most of the time we just use kill -9 to kill a process forcefully , there are many other signals that can be used with kill. But i wonder what are the use cases ...
3
votes
4answers
348 views

How do you create a for loop with a changeable number of iterations?

How do you iterate through a loop n amount of times when n is specified by the user at the beginning? I have written a shell script and need to repeat a certain part of it n numbers of times ...
3
votes
1answer
47 views

Dropping a connection upon event

Is it possible to drop a number of connections when establishing new ones? For example, suppose we have a set of remote workstations with addresses {A, B, C} and another set with hosts {D, E}. We ...
3
votes
2answers
97 views

Find all files modified around a known one

An installer which isn't really clean (Adobe Acrobat Reader DC) installed on my Unix (Mac OS X) a lot of files in different places. I have a reference file Application which I am pretty sure was ...
2
votes
1answer
65 views

See if a script is running when using #!/usr/bin/env

I have tried migrating the shebang for my bash scripts from #!/bin/bash to #!/usr/bin/env bash, and some of them were broken because they relied on this code that checks for existing instances of ...
2
votes
2answers
59 views

How to duplicate a file a number of times while embedding an index in each file

I have a file named, for example, ascdrgi.txt, with the following contents: tiger lion cat I want to duplicate this file a (variable) number of times by changing the last character of the filename ...
2
votes
1answer
28 views

Bash scripting to process an experiment data file

I have a .txt file with a sample snapshot of the content shown below. I have to sum all the field values and output them. That is, sum total CEPSDIST (MEAN), sum total SRMR, etc. I want to use bash ...
2
votes
1answer
44 views

Extract URL from non-formatted text

I've found only examples on extracting substrings from formatted text like HTML files, but in my case I need to output a list of URLs for example: ... https://twitter.com/user1/status/xyza ...
3
votes
2answers
328 views

The type command can't distinguish between an executable command and a shell script

So I was reading the book The Linux Command Line, and it says that commands are of four types: (1) executable programs (2) shell builtins (3) shell functions (shell scripts) (4) ...
3
votes
1answer
66 views

Split line to words of maximum size of 8 characters

I'm creating script that will display 2 times the song name in FM radio station name. Radio station name is limited to 8 characters. Lets say I have this line: Best Direction - I feel good The code ...
-1
votes
1answer
25 views

Comparing values in one same string [closed]

In my script, Im getting data from website, like that: content=$(wget 10.0.1.5:8000/currentsong?sid=1 -q -O -); It's basicaly song information on shoutcast server. But there is the problem: I like ...
4
votes
4answers
111 views

Extracting strings from between special characters

I have a large text file created from combining lots of html files. cat *.html > all_html_files.txt Inside the text file are specfic strings that I want to extract to another text file. For ...
1
vote
1answer
107 views

Unable to store command output in variable

I am executing below script but i get an error "line 14: last-tag=TSTA-6: command not found" i.e. at the point i try to store the command output in variable (TSTA-6 is output of command). Any ideas ...
1
vote
0answers
12 views

Need Help to Solve Screenlock Bypass Issue for Expired User Account

I have created a script that I deploy to my children's computers via Salt. The script implements allowed working hours and has worked well, but one of my children have found a way of bypassing this ...
2
votes
2answers
38 views

Is it possible to display a running timer in a shell script while copying a directory?

So I have a shell script that basicly backs up one server to another server. In the process I have to cp a very large directory (140GB) to another location, in the shell script I would love to have ...
-4
votes
1answer
51 views

How to transform row to collumn in csv file?

2015-12-2119:30:00;ManagedElement=1,Equipment=1,Subrack=1 ;pmEs ;0 I need this result 2015-12-2119:30:00;ManagedElement=1,Equipment=1,Subrack=1;pmEs;0 Extra data from comment: 2015-12-21 ...
1
vote
1answer
84 views

Bash script to select files to zip/unzip

I'm trying to zip and unzip files with a bash script, but I'm new and I have problems. I will explain what the script currently does, and then what I wanted it to do. User selects “compress”: a file ...