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

learn more… | top users | synonyms (2)

1
vote
1answer
26 views

cannot get screen command to execute code containing DISPLAY=:0

I am trying to ssh into a remote machine and run a shell script, which opens a GUI. I want the GUI to open on the remote machine and remain open (so I am using DISPLAY=:0 nohup). I tried: ssh -t ...
0
votes
1answer
20 views

Dynamically write bash script from another?

I am trying to dynamically create and write to a file a bash script from from a current bash script. echo "## Get the IP of the system that was assigned #!/bin/bash ip=$( hostname -i | xargs ) echo ...
0
votes
1answer
20 views

Including milliseconds in a Script?

sudo hexdump -v -e '1/1 "%02x\n"' /dev/ttyUSB0 | awk '$1=="ed" { getline byte1 getline byte2 number = strtonum("0x" substr(byte2,2,1))+2 ...
0
votes
1answer
9 views

Setting XDG_CACHE_HOME Breaks Firefox Installation

In my .bashrc I set my XDG_CACHE_HOME variable to "~/.cache/". This breaks my Firefox installation, telling me that it cannot load my profile. Without this line, Firefox loads properly. I have ...
0
votes
1answer
20 views

printf in my output now

The encryption on this problem just got more interesting. I started with this script: while read CTFlist; do #next we need to create ctfs padded with zeros as a variable ctfPadded=(printf ...
-1
votes
1answer
39 views

add multiple .csv files using bash command

I want to iterate over all randomly generated CSV files in a folder using using bash and add them line by line. Each CSV files has 3 rows, the 1st row indicates just the number of generated files and ...
-1
votes
2answers
41 views

Use of && and || operators to handle the result of the same command

In bash, is it possible to use these two operators to handle both of the exit statuses of the same command ? or if I want to handle both cases, I have to use an if statement ?
0
votes
3answers
46 views

sed substitution

I have a string as follows: /test/test/ 12 /test/test My goal is to turn it into: /test/est/ 12 /test/test This is the command: echo "$x" | sed 's@\(/*/\).@\1@g'" I am using at the moment but ...
0
votes
0answers
18 views

Script generating dummy file with same content of my script while running my script [closed]

I have a script (bit huge, so I could not post here). When I run the script: sh /home/user1/myscript.sh It generates a file named 1 (or sometimes ?). If I open the file with: vi /home/user1/1 # or ...
2
votes
2answers
284 views

How can I redirect the output of a child process?

I am running the following git clone command through sudo and bash and I want to redirect STDOUT to a log file: % sudo -u test_user bash -c "git clone https://github.com/scrooloose/nerdtree.git ...
0
votes
1answer
32 views

getting links including outer html

From a html page with lots of links, I'm looking for a way to extract only the links that follow a specific format. <a href="https://always/same/link/same-name_19.html">always same ...
-1
votes
0answers
28 views

Shell Script- Conversion script for reading and updating data to new column

I am writing a conversion script that will help me to read the data from a column and move it to a new column. I want to read data row by row for column cross_reference and copy this data to newly ...
0
votes
2answers
46 views

Binding Timestamp with Hexdump?

I am running a script which is given below, sudo hexdump -v -e '1/1 "%02x\n"' /dev/ttyUSB0 | Many Pipes | gawk '{ print strftime(":: %s"), $0 }' Here the data is being hex dumped with timestamp ...
0
votes
0answers
52 views

Issue with the ftp script [closed]

I am trying to run a script which ftp the files from one server to another. Below is the script - #!/bin/bash echo "Please enter no : " read variable echo "You entered: $variable" HOST=xxxxx ...
0
votes
3answers
37 views

BASH: pass arguments to sub-script

I have a script like this: #!/bin/bash . config ./sub-script There are a lot of variables in config and I don't want to pass them to sub-scirpt like ./subscript arg1 arg2 ... arg100500. Also, I ...
-1
votes
0answers
32 views

Read and filter mail by subject line through a shell script [closed]

I need to configure a shell script which would periodically check the incoming emails, and looks for an email with a particular subject line. It then needs to download and move the attachment from ...
0
votes
0answers
29 views

How can I create a script to do not mount pendrives for some time?

I'm new to Linux (I'm using Ubuntu 14.04) and I want to create a script to deny pendrive mounting. What I want: root user deny pendrive mounting to everybody except him for 4 hours. More: how to ...
0
votes
5answers
64 views

Adding time stamp to a log file?

I am running a script file. I have written a while loop inside the script in which I have pipelined multiple commands like awk, sed and finally I am writing the output to a file using > operator. I ...
0
votes
1answer
21 views

Bash script using mysql command with variables failing

I have a script to clone a vhost and associated db - however one of the mysql commands doesn't work. It fails and ends up outputting the mysql version number and 'how to use' info as if it hasn't been ...
-2
votes
2answers
53 views

standard deviation using awk [closed]

I am using below command to get standard deviation of file A names 1 2 3 avg 23.3107 20.0372 21.7236 21.6905 awk '{x[NR]=$0 ;} END{a=$4; for (i in x){ss += ...
1
vote
1answer
44 views

Creating a complex variable content by hand

I am creating a shell script dynamically and sending it to a remote server for execution. All is working except when I try to inject a variable with content coming from a file with multiple lines, ...
0
votes
6answers
100 views

how to do formatting of a file in unix

I have a file file.txt. which have below three records. <ResultDescxmlns="http://www.mpaet.com/boe/interface/common">Operation successful. 220095 9251000014 Now my desired format should be as ...
0
votes
1answer
82 views

Bash script commands execution wrong order [closed]

I have the following script: #!/usr/bin/env bash #Find the IP via ping ping=$(ping federicolivieri.noip.me -c 1) #Edit the ping output and grab the IP ip=$(echo ${ping} | awk '{print $3}' | rev | ...
-7
votes
0answers
18 views

how to create domain user [closed]

question Lists in a list item: - Indented four spaces. * indented eight spaces. - Four spaces again. 2. Multiple paragraphs in a list items: It's best to indent the paragraphs ...
0
votes
1answer
34 views

How to replace a text in a shell executable file (.sh) using Python?

I have xxx.sh file which content is: setsid ./start-meteor.sh >> /home/farah/StudioInstallation/Studio/bricks/platform/log/databricksastro.log 2>&1 < /dev/null & I want to ...
1
vote
1answer
47 views

BASH Variable checker function

I am struggling to figure out a way to reduce code duplication. Specifically when checking if a variable is set. My code currently looks like this: # webadmin enabled if [ -f "${servercfgfullpath}" ...
0
votes
2answers
94 views

Why does `read` not pick up all my vars?

My apologies for the very basic question, but can someone please help explain why the following does not print 3 2 1 6 5 4? echo '1 2 3 4 5 6' | while read a b c; do echo result: $c b a; done ...
0
votes
0answers
53 views

Executing remote code with arguments

Why this: ssh -i ~/.ssh/master.pem ec2-user@xx.xx.xx.xx 'bash -s' < `dirname $0`/elements/"$element" returns hostname.sh test-5000: No such file or directory when $element is not a just a single ...
-1
votes
2answers
77 views

Script that will show area of rectangle

I am looking to write a script which will prompt the user for two numbers, representing the width and height of a rectangle in centimetres, and output the area of the rectangle in both square metres ...
-1
votes
1answer
32 views

Arithmetic expressions in for-loop

In for (( expr1 ; expr2 ; expr3 )) ; do commands ; done expr1, expr2, and expr3 are arithmetic expressions. Is expr1 ; expr2 ; expr3 not an arithmetic expression? (( expr1 ; expr2 ; expr3 )) ...
3
votes
3answers
35 views

How to pass array to bash shell script?

How do I pass an array as a variable from a first bash shell script to a second script. first.sh #!/bin/bash AR=('foo' 'bar' 'baz' 'bat') sh second.sh "$AR" # foo sh second.sh "${AR[@]}" # foo ...
2
votes
1answer
25 views

Bash shell script program that prompts for and reads two integers from the user.

Okay, so I been trying to figure this problem for a while and I'm coming up with errors left and right. This is my first time trying to learn the basics. So any advice would be helpful! Problem: I'm ...
2
votes
2answers
55 views

Accessing array index variable from bash shell script loop?

I want to access the array index variable while looping thru an array in my bash shell script. myscript.sh #!/bin/bash AR=('foo' 'bar' 'baz' 'bat') for i in ${AR[*]}; do echo $i done The result ...
0
votes
1answer
24 views

Automating Backup and Shutdown

I want to backup my entire internal hard drive files into an external hardrive and execute system shutdown once the backup is finished. The reason why I want to do that is to execute the backup during ...
1
vote
1answer
30 views

Join two files in a batch mode

I have many files with the following names: 0001mm.xyz , 0002mm.xyz , 0003mm.xyz ... 0001qm.xyz , 0002qm.xyz , 0003qm.xyz ... I want to join the contents of 0001mm.xyz and 0001qm.xyz ...
-3
votes
0answers
26 views

Checking for sequence of numbers received through stdin in a loop using shell script?

I have a pipe line like this: foo | bar | baz (shell script?) The bar program sends through the pipe to baz a string formed like this: Code: 1 Code: 2 Code: 3 I want to cut "Code" part, collect a ...
3
votes
2answers
63 views

Changing a file's modified date based on date in file name

I have a directory full of photos with file names in this format: IMG-20160305-WA0001.jpg. The date taken is obviously in the file title. Unfortunately the date modified on all files is today. I ...
3
votes
3answers
195 views

Why and when should eval use be avoided in shell scripts? [duplicate]

Many answers and comments on this site mention that one should generally avoid using eval in shell scripts. Often these comments are addressed to beginners. I've seen mention of security issues and ...
1
vote
1answer
41 views

Aligning Hexdump Data in a Specific format?

I am reading serial data from my Raspberry Pi and all I am doing is a Hexdump I have to find the header and then go to the 2nd byte of data from header for ex: ed 13 74, I have to take the value 4 , ...
0
votes
4answers
44 views

Setting variables from shell: how to use them in a script?

How can I set variables to be used in scripts as well? They don't have to be global / system-wide, just the current session is sufficient. But for some reason they seem gone even if I run a script ...
1
vote
2answers
40 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
40 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
33 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
44 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: ...
0
votes
1answer
56 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
36 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
30 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
votes
0answers
35 views

How can I print the result of a tr command through a variable

I am using the command below: echo "$file1" | tr "\n" "," It is printing results like this: rose,lotus,jasmine,marigold If I assign the result to a variable it is printing output like this: $r ...
1
vote
1answer
35 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 ...
-5
votes
1answer
49 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 ...