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

learn more… | top users | synonyms (2)

2
votes
3answers
55 views

Use a wildcard in directory path

I'm trying to write a bash script where part of a directory is a long, unknown string. I know the first part of the directory name. How do I combine the known string and the wildcard in the path? As ...
1
vote
2answers
42 views

Extract zip files into directory based on pattern of zip name

I have these zip files: PLP_633555_2015-03-04_01-12-01.zip PLP_634562_2004-03-02_02-15-07_UBIC.zip PLP_563462_2008-05-02_01-21-03_UBIC_STOC.zip And I need each zip extracted into its appropriate ...
2
votes
4answers
74 views

How to format a bash loop using sed, awk, grep, and wc

So I have a text file that I need to get extract specific lines out of and count the number of times a number in a specific column appears. I have about 100 or so of these files. I can get it done ...
0
votes
1answer
46 views

Why would this script work with bash on Kali, but not with bash on Xubuntu?

I have a script that I made when I was at home on a Kali virtual machine. It works perfectly there, but now I'm at work on my Xubuntu install and it's not working at all. The exact shell that I'm ...
3
votes
3answers
73 views

Replace a long string with the sed command: Argument list too long error

I'm trying to execute this command sed -i -e "s/BASE_64/$BASE_64/" FILE_NAME where $BASE_64 is a base 64 representation of a file content. sed gives me an error since the string is too long. ...
1
vote
4answers
54 views

How to gather the name of the files in each subdirectory into a text file in that subdirectory?

I wanted to save the names of all files in each sub directory into a text file in that sub directory, so I wrote this script: #!/bin/bash for X in "$PWD" * do if [ -d "$X" ]; then ...
0
votes
1answer
19 views

Why does the jobs command not work in shell script?

If I run jobs -l on command prompt it shows me the status of running jobs but if I run below file ./tmp.sh #! /bin/bash jobs -l It shows empty output. Why is that and how can I obtain information ...
0
votes
0answers
37 views

sed can't find file on a shell script [duplicate]

I've been running into a problem whenever I run the shell script containing a sed. If I try this argument by running the shell script with the following line, it gives me a bizarre error: arg=$1; ...
0
votes
1answer
60 views

inserting modified date into filename - 2 cases

I believe I'll ask two separate questions, but the context is the same, so I hope it's alright. I have an output of few processes as presented below (which I can't modify). 25978.csv 26044.csv ...
0
votes
1answer
59 views

How to write bash script while using command as condition in if statement?

I am writing a bash script to process input from html form. I have two issues which I can't seem to be able to figure out. I am a beginner to Unix. First problem is that I can't get my if statement ...
1
vote
3answers
95 views

How can I compare different files without opening them?

I have two directories A and B; each one contains a lot of sub-directories geom001, geom002 ....etc each sub-directory contains a file named results. I want to compare, without opening any of ...
0
votes
0answers
95 views

Start vino-server in Ubuntu 16.04 lts

I'm trying to raise vino-server in Ubuntu 16.04 but I could not. I am using this script and let me start by terminal: # /etc/init.d/vino-server.sh start but not as a cronjob: @reboot ...
2
votes
1answer
28 views

( test -n $st ) != ( test -z $st ) right?

As I read, test -n $string ==> Exit status is 0 if $string is not null, 1 otherwise and test -z $string ==> Exit status is 0 if $string is null, 1 otherwise But in this particular example, (I ...
1
vote
1answer
21 views

Question about if structure and loops

I am new in programing with bash script. Here is my problem: I am going to open a sort of data whose file name includes the date (format: file_yyyymmddhh.nc). There are some requirements: mm is ...
3
votes
2answers
52 views

Is there a reason to use “[ ! -f file ] || command” instead of “[ -f file ] && command”?

I found [ ! -f /etc/default/lxc-net ] || . /etc/default/lxc-net in /etc/default/lxc on Ubuntu 16.04 which seems to be replacing (my own or package maintainer code) [ -f /etc/default/lxc-net ] ...
0
votes
3answers
154 views

Where can I find the shell script for ls command? [closed]

I am trying to understand how the ls command works, and I presume there is a shell script which defines ls somewhere in the filesystem. This correct? If so, where can I find it?
0
votes
0answers
38 views

Understanding bash script for getting drop down option

I have this script which reads the user input for executing some command, This is working fine. User=0 Path="/root/file/" Path1="/root/domain/samples/file" echo "Please select k1 l3 l8 o5 s2 s1 ...
2
votes
2answers
43 views

How can I more efficiently collect data from users on a vm?

I'm teaching a course this summer. My students' first assignment will be to install a virtual machine that I created (the machine will run Ubuntu). Upon installation they are to run the following ...
1
vote
1answer
48 views

How to enable CURL in UNIX server? [closed]

I have to make a web service call through CURL in shell script. For this, CURL should be enabled. Below is my server details: Sun Microsystems Inc. SunOS 5.10 Generic January 2005 below is ...
11
votes
1answer
167 views

Why do these bash fork bombs work differently and what is the significance of & in it?

I get how a normal fork bomb works, but I don't really understand why the & at the end of the common bash fork bomb is required and why these scripts behave differently: :(){ (:) | (:) }; : and ...
11
votes
1answer
531 views

Is there any way to tell if a shell script was killed with signal 9

I have a bash script (called from a java program) that keeps getting killed. I always catch the signal 15 with trap but then some other signal comes along that I suspect is signal 9 but am in ...
0
votes
1answer
44 views

Why this option not working in this Bash script?

I am expanding the following function to include the option -i | --ignore-case with error-handling #!/bin/sh [ $# -ne 1 ] && echo "1 argument is needed" && exit 1 find $HOME -type f ...
-1
votes
0answers
35 views

how to pass multiple column value in a command

I have a file oldnewmap.txt. This file has hundreds of records like the following, where column one represents oldnumber and column two represents newnumber. 21382,45678 34567,45663 44245,42455 ...
1
vote
1answer
20 views

linux periodic system check script or utility [duplicate]

Is there any commonly used shell script or utility to periodically check Linux file systems for changes, such as permission or ownership changes of configuration files. I am thinking of something ...
-1
votes
1answer
56 views

What's the meaning of this variable in Bash script?

So this is short script used to rename extension of files i found on tldp. #!/bin/bash Mysterious=65 case $# in 0|1) echo "Usage: `basename $0` old_file_extension new_file_extension" exit ...
1
vote
0answers
41 views

Changing permissions of the file, while using sftp command in a shell script

How can I change the permissions of the file/command, while using the sftp command via a shell script? My sftp connection is established, but it fails while executing the chmod command. As of now, I ...
1
vote
1answer
44 views

Get run time for two programs simultaneously

I am trying to make a shell script that could run tests on two differents programs simultaneously and compare their runtime in order to see which one has the best efficiency (tests have to be ...
0
votes
0answers
23 views

What is the difference between '[' and '[['? [duplicate]

(Hope this is no duplicate) So I have a part of script like this: $ a='f' $ [ $a = [fF] ] && echo yes || echo no no $ [[ $a = [fF] ]] && echo yes || echo no yes So, why do the ...
1
vote
1answer
34 views

How can I edit my bash script to account for whitespace entries? [duplicate]

I made a script to automate ffmpeg conversion from mkv > m4v > open the m4v in Subler.app to import the metadata manually, at which point I'll move the file into my iTunes library. I use iTunes ...
3
votes
1answer
39 views

Bash: Why is read returning a nonzero exit status while reading my file?

I'm trying to read two files line-by-line in Bash and do something to each of their lines. Here is my Bash script: #!/usr/bin/env bash die() { echo "$@" >&2 exit 1 } extract_char() { ...
3
votes
1answer
39 views

Can I somehow update compressed archives?

I'm trying to find all files with given extension but I'm getting this error: tar: Cannot update compressed archives Try 'tar --help' or 'tar --usage' for more information. tar: Cannot update ...
0
votes
1answer
40 views

why looping over string is different when it's in a variable

I am wondering why when you iterate over a variable n="1 2 3" you get this: $ n="1 2 3"; for a in $n; do echo $a $a $a; done 1 1 1 2 2 2 3 3 3 but if you don't put the string in a variable first ...
2
votes
0answers
39 views

How to get the executed command of a process which has completed successfully using the PID?

I have small script, abc.ksh that takes 3 parameter e.g abc.ksh ${a} ${b} ${c} I will read from a config file with 'n' no of entires and I will execute abc.ksh 'n' times in parallel using a for loop. ...
2
votes
2answers
89 views

Using tar with find

Lets say we want to find a certain files , use tar on them and delete them. I tried using touch "mycompress.bz2.tar" find . \( -name "*.c" -o -name "*.sh*" \) -exec tar ujf "mycompress.bz2.tar" {} ...
0
votes
2answers
37 views

Awk: Print last N columns, where N is passed through a variable

My input variable $dirPath contains directory path. The action is to be able to retrieve the last N values in the directory path, where N is passed through a variable $depth. For a fixed N value (say ...
0
votes
1answer
55 views

Prepare update command using sed

I have a output file that contains 3 different column data- ['AARF'],SAMPLE12,2016-01-05 12:00:00-0500 ,529OFFST,2015-04-16 08:04:21-0400 "['EPROSP_IWS', ...
1
vote
1answer
39 views

Find All images file size and width in directory

I'm trying to find all .png .jpg and .gif files in my directory. I'm getting the file sizes properly but unable to get image width (I'm using imagemagick) in log file. Script code #!/bin/bash for d ...
1
vote
2answers
30 views

Repeating current loop iteration if some condition is met (bash)

I'm writing a bash script which takes files and directories as arguments. It will loop through its arguments and rename the current argument if some condition is met. When this happens I want also to ...
2
votes
3answers
35 views

echo all *.tex filenames in a specific directory

I have a directory structure like this: ├── lebenslauf │   ├── lebenslauf.out │   └── lebenslauf.tex ├── thirdPage │   ├── auto │   │   ├── test.el │   │   └── thirdPage.el │   ├── missfont.log │   ...
0
votes
3answers
64 views

Defining bash function dynamically using eval

I'm trying to define a bash function dynamically using following code: delegate_function() { echo "output from delegate"; } eval "parent_function() { echo $(delegate_function); }" The intent is to ...
3
votes
2answers
25 views

Improving execution speed of Screen Brightness Script

xrandr --output LVDS-1 --brightness $(bc -l <<<"$(sed 's/Brightness: //' <<<$(xrandr --prop --verbose | grep Brightness)) $(if [ "$1" = "+" ];then echo +;else echo -;fi) 0.1") I ...
0
votes
2answers
57 views

How to run a shell script on 10 hosts simultaneously? [duplicate]

Currently I am monitoring 10 hosts. I want to write a script which will calculate the disk space in every 24 hours and then if the file system of a host is critical for any host then it will move the ...
0
votes
1answer
24 views

jq capture - how to properly key with captured string

I routinely use lshw -json to abstract system data on Linux hosts. In the current scenario, I've extracted network data from lshw via lshw -c network -json and have need of extracting, further, data ...
1
vote
2answers
38 views

Scope of Local Variables in Shell Functions

After reading 24.2. Local Variables, I thought that declaring a variable var with the keyword local meant that var's value was only accessible within the block of code delimited by the curly braces of ...
1
vote
0answers
21 views

How to write decorator commands [duplicate]

I don't know the exact word, that's why I'll use "decorator", like in POO, but I'm talking about the kind of functions you can use before other functions to add any operations to it, like the command ...
1
vote
1answer
31 views

How to run a for loop block which is within a shell script after connecting to another server using sftp?

The script.sh takes a list.txt (which contains list of files present on both server A and server B) file as command line parameter and reads the list .It then connects to server B using sftp and ...
-5
votes
1answer
57 views

Exit a program by pressing the key q

I have wrote a shell script in which I would like to include the functionality to exit the program by pressing the q key. Can I do that? Here is what I currently have: #!/bin/ksh echo "Press Q to ...
0
votes
2answers
34 views

Daemon to: receive messages -> run background command -> manage number of tasks running simulatenously?

Looking for a unix program that runs in the background (daemon), that: can receive arbitrary (JSON) messages. On receiving a message, run a specified command. Has option for limiting number of ...
1
vote
3answers
69 views

Using time on bash functions (not commands)

How can one measure individual calls to bash functions from inside the bash file. I have a program that I call using the command eclipse -b col_solve.pl -e "myPred" This call outputs some ...
2
votes
3answers
40 views

Bash read with delimiter past newlines

I have a csv for which I have to extract a specific field. The csv is pipe-delimited (|), with double quotes (") to protect text fields and (this is the catch) newlines in some of the text. eg. ...