Questions about bash only, as opposed to other Bourne/POSIX shells. For all Bourne/POSIX-style shells, use the /shell tag instead.

learn more… | top users | synonyms

0
votes
1answer
22 views

Create variables and assign values via loop (bash)

Is there a way to create bash variables and assign them values via a loop? Something along the lines of: #!/bin/bash c=0 for file in $( ls ); do var"$c"="$file"; let c=$c+1; done EDIT: ...
0
votes
2answers
51 views

How can I select 3 character files in Bash?

I know that a question mark is considered a special character and it has special meaning. Question mark represents a single character that can be any type. In my practice lesson we have an example : ...
1
vote
1answer
15 views

custom nemo actions / bash script

i am trying to add a custom action to the nemo file manager. The purpose of the action is just to replace all whitespace in the filename by "_". My action file looks like this: [Nemo Action] ...
0
votes
0answers
18 views

Sqlplus environnement error

I have two virtual machines ubuntu, one is a server when I installed oracle 11g express, and the other is a simple client. My goal is to run an sql query remotely from the client machine. So I ...
1
vote
1answer
43 views

Why doesn't /bin/login appear in ps output when someone is logging in

I wanted to monitor what happens when a test user logs in to my CentOS 6.4 system, so I tried this to poll ps for /bin/login and strace the pid when it appears: until [[ $(ps -ef|grep -q [l]ogin)$? ...
1
vote
1answer
40 views

bash: -eq vs. == and `bc` output type

This snippet of code has been taken from a larger script, (humbly) simulating the non-existing abs() function: [[ $(echo "$val < 0" | bc) -eq 1 ]] && val=$(echo "$val * -1" | bc) So we ...
2
votes
2answers
37 views

Local variable as a part of global one

I have a question about something similar to this question, but I need to call global variable depending on local one. Say I want to pass either test, staging, or production as a variable to a ...
0
votes
1answer
21 views

sqldeveloper can't start

When starting sqldeveloper it crashes without any warning. It just shows a window for a fraction of second. By debuging : $ bash -vx /opt/sqldeveloper/sqldeveloper/bin/sqldeveloper it gives this ...
2
votes
1answer
13 views

Recover last argument of the last command in bash' vi mode

When using bash's vi mode (set -o vi), is it possible to recover the last argument of the last executed command? This is done in emacs mode with ESC+., and I would like to do it in vi mode as well. I ...
0
votes
1answer
6 views

Remap cursor keys in bash vi mode to <nop> (disable cursors)

When using vi mode (set -o vi) with Bash, is it possible to remap the cursor keys to so that they don't work (and be forced to use h, j, k and l movement keys)? Under vim (the editor), I can do it ...
1
vote
2answers
48 views

Log both stdin and stdout of program

What I want though is to run a program and log both the stdin and stdout, but I want the stdin to be supplied from a file. I thought script log.txt < input.txt would work, but it does not, because ...
2
votes
2answers
49 views

list all c files in sub directories and their parent directory

Assume I have a directory tree as follow: /home/xen/p.c /home/dan/t.c /home/jhon/l.c ... etc (many more users) I need to get comma separated (username,full path to c file) list as follow: ...
1
vote
1answer
21 views

Setting environment vars containing space with env

I'm trying to use env to set environment variables (read from another source, say for example a file) for a subprocess. Essentially, I am attempting the following: env VALUE=thisisatest ...
3
votes
1answer
27 views

Why does my application die without nohup?

I have a simple system (running on Debian) that works by invoking a script from /etc/init.d/rc.local At the bottom of rc.local I call myScript.sh who sets up some things, and then starts a binary ...
0
votes
1answer
24 views

How to echo tac'ed file into a new file [on hold]

I've got a blonde moment. How can I print this into a file: tac /driectory/somedirectory/myinputfile.csv | grep StackExchange | grep ',scan' | grep -v 'HDCU.*HDCU' | grep -v 'Sensor,Module' | ...
2
votes
0answers
40 views

Fixing my PATH variable

I am perplexed by the following problem and hoping someone can help me fix it: when I type echo $PATH, I get the output: /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games However, I ...
4
votes
2answers
181 views

Best and short way to run a program if another is not installed

I have this code: #!/bin/bash num=${1:-undefined} cmd=$(which {banner,echo} | head -n1) until [[ "$num" =~ ^[0-9]+$ ]]; do read -p "Type a number: " num done for ((num;num>=0;num--)); do ...
2
votes
2answers
40 views

cp won't work on current bash script's directory

I'm trying to copy some files from current directory in a bash script but the problem is that the cp command doesn't work with the current directory. I can use the following command without any ...
3
votes
3answers
158 views

Environment variables. Where are they saved in? [duplicate]

If I do not edit the .bashrc or other config files, the environment variables that I've setted are gone when I logout, or turn off the terminal. What I'm curious is, where are those 'temporary' env ...
0
votes
1answer
33 views

Color diff output

I am new to unix I wanted to format the unix files conditionally , I am currently working on diff command and wanted to know if it is possible to format the text of the diff command output. Example: ...
0
votes
1answer
46 views

How can I get a shell script to change directory for me? [duplicate]

here is a small test I ran, to try and move me back to root: #!/bin/bash pwd cd / pwd It returns the current working directory, and then the correct new one, but when the script finished executing, ...
0
votes
1answer
22 views

Hide curl output [duplicate]

I'm making a curl request where it displays an html output in the console like this <b>Warning</b>: Cannot modify header information - headers already sent by (output started at ...
-1
votes
0answers
36 views

Bash read user input and then call for a curl [duplicate]

I'm trying to execute a bash script that accepts user input and then according to that user input executes a curl request, the user input includes the query string that should be called using curl. ...
-2
votes
0answers
29 views

Unix KSH/Bash : Diff files for selected fields/columnwise only {GNU Bash 4.2 Environment}

I have two files: F1: abc|abc|abc|abc|abc| abc|abc|abc|abc|abc| abc|abc|abc|abc|abc| F2 abc|abc|abc|abc|abc| bcd|bcd|bcd|bcd|bcd| My questions are as follows: Suppose both files will have same ...
4
votes
4answers
282 views

How do I extract parts of a string to variables?

I have a line from some file like this: attempting to create a 512^3 level (with Dirichlet BC) using a 16^3 grid of 32^3 boxes and 800 tasks... I want to extract the 512^3, 16^3, 32^3 and 800 four ...
0
votes
1answer
24 views

Sanitise bash arguments

I have a script which takes user input and does a lot of things. One thing which I am worried about is it takes a file name and removes that file. e.g. rm -rf $arg1. A user could technically input / ...
1
vote
4answers
35 views

Anyway to pass a variable to bc, having a command to be executed?

I need to pass certain variable to bc to get the output in floating point, var1=$((<some operation>)) var2=$((<some operation>)) #Needs var1 var3=$((<some operation>)) ...
-3
votes
0answers
22 views

Write a script that will send the following information to the [on hold]

Write a script that will send the following information to the screen, in the following format: Month Sales ===== ==== January 200 February 300 March 200 April 200 May ...
-5
votes
2answers
57 views

How to average a column in a text file without using ' character? [on hold]

I need to do it without using the ' character. I could do it like this: awk '{sum+=$5} END { print "Average = ",sum/NR}' except this contains a '.
3
votes
1answer
37 views

Is it good practice to make an init script's lockfile immutable?

I recently created an init script, and decided to set lockfile to immutable to prevent external interference. The only downside I can think of is that if someone wanted to recursively delete ...
1
vote
2answers
72 views

One-Liner needed: Stop httpd if running already & Start httpd if not running

As part of a provisioning script for CentOS 7 I am in need to have a one-liner that performs the following. Unfortunately, I have no clue how to achieve that. If httpd is running then stop it If ...
0
votes
1answer
65 views

How to get rid of “\r” a the end of the line comming from pipeline in bash

#!/bin/bash sourcenode=$1 destnode=$2 path1=/root/test ssh root@"${sourcenode}" -t "echo "${path1}" | xargs -IDIR find DIR " | while read line do ssh root@"${sourcenode}" -t "stat -c "%a" ...
3
votes
2answers
27 views

locally created alias not being used if called using backticks (`)

I have come across this issue while trying to build up a script to do grep on multiple files for 10 different word. The script I created, is (minified) #!bin/bash alias grep='grep -n' out=`grep word ...
0
votes
0answers
23 views

Edit Oracle Path on Ubuntu Virtual Machine

I have two virtual machines ubuntu 14.04 LTS, one is a server when I installed oracle 11g express, and the other is a simple client. My goal is to run an sql query remotely from the client machine. So ...
1
vote
1answer
34 views

Compare n no of column values between each record in 2 files and apend data from file 2 to file 1

I am new to unix so wanted to understand how this(mentioned below) can be done. I have an input file like this: Example for input file: a|a1|a2|a3|a4|a5|...|a29|$2342 a|a1|a2|a3|a4|a5|...|a29|$2343 ...
0
votes
0answers
51 views

De-dup the file based on combination of fields and store the last value for duplicates

Scenario is like: I have a sorted input file(pipe delimited) which has dupes (except last column value) in it. Now i need to check each of my input lines and decide if it's duplicate. If yes then ...
1
vote
2answers
27 views

How to merge the lines in Unix (Sun Solaris) in a specific pattern

I have below n number of lines in a flat file: uk,1234560000 uk,6789067000 uk,4567890000 . . . n lines Now I have to make it in below format: ...
1
vote
1answer
73 views

Using the grep filter

I have a text file with the name "hello.txt" that contains the following two lines: Hello WORLD! Hallo world! When I wrote the following grep -i h[ae]llo hello.txt in the terminal, the output ...
0
votes
1answer
21 views

Nnumber of HTML redirects from cURL

My little script extracts DOI's from a csv files in order to check whether they are right. The number should equal 3, and if it doesn't, I want to output an message. #!/bin/bash ...
0
votes
1answer
10 views

How to redirect output of a 'xterm -hold -e' command

I know you can use tee to log output from a command in a terminal, e.g.: df -h | tee ~/log.txt However, how can I do this with a more complex command like this: xterm -hold -e program arg1 arg2 ...
0
votes
0answers
10 views

trap to debug signal was evoked twice before shell function executed when 'functrace' is on

My aim is to do something before every user-defined function executed. The most straightforward method coming to my head is to use trap to debug signal. The pilot script run quite well: #! /bin/env ...
0
votes
1answer
45 views

Hyphens in variable values (in bash) [on hold]

I'm writing a simple script for iptables to restrict access using MAC addresses. First, I check if an address has been passed to the script: ALLOWED_MAC=$5 MAC_STRING="" if [ -n "$ALLOWED_MAC" ] ; ...
2
votes
5answers
370 views

Problems when trying to execute sh file from another sh file

I have the following script: #!/bin/bash if test -f "/path/pycharm.sh"; then sh ./pycharm.sh; fi I am trying to run pycharm.sh from a bash file and I've looked carefully to give all the ...
0
votes
2answers
49 views

Writing a Script to match the architecture of system and software

I am trying to write a script where it will cross check to things: 1.The architecture for which the setup file was intended (32 or 64 bit) 2.The Architecture of the system. The second part is quite ...
0
votes
1answer
38 views

shell script unable to set environment variable with the grepped value

In the shell script, I want to grep a value from the log file and set as the value of one environment. In the log file, there is one line like this: SOME_PATH=/some/specific/path In my shell ...
2
votes
1answer
41 views

Using fixed strings in regular expressions?

I am writing a bash script which accepts a list of CSV files as arguments and outputs e-mail addresses only found in the first file. To accomplish this, for each record in the first CSV file I look ...
1
vote
1answer
34 views

Cut some fields from a text file to another

I have the following command: grep -owf champs.txt t.txt and I want to cut the result of this command from the file t.txt to another file. I know that it can be achieved by a nested command but I ...
2
votes
2answers
81 views

Passing a bash command line arguments containing #

I am trying to pass pound sign as a command line argument then echoing the argument. When I pass for example 2 # 2 then I echo $1 $2 $3, I assume the terminal will output 2 # 2 but it outputs just 2. ...
3
votes
3answers
101 views

Bash script command line argument to upper case

If I can do this in my bash shell: $ STRING="A String" $ echo ${STRING^^} A STRING How can I change my command line argument to upper case? I tried: GUARD=${1^^} This line produces Bad ...
0
votes
2answers
31 views

Auto Delete Inactive files after x

Is there a way I could delete certain folders after x amount of days of inactivity? I was thinking of using cron but that wouldn't take the inactivity part into consideration. Is there any Debian ...