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
0answers
10 views

Delete Non numeric row from a csv

I have used sed to allow only numeric and csv format ,I have used sed '/[^0-9, -, .]/d' as regex. It has still "_","1-0","1-1" character as o/p which worries me. sed 's/'"$(printf '\015')"'//g' ...
1
vote
3answers
25 views

How to alias rm to always confirm

When I use the command rm -rf, I want to make sure a prompt always appears before deleting a file, so I tried adding this to ~/.bashrc alias 'rm -rf'='rm -rfi' But it doesn't work. How can I fix ...
0
votes
1answer
19 views

creation of a variable, and assignment of a value to the variable

From Bash manual, a parameter is set if it has been assigned a value. In bash, are the following two different concepts: a variable exists a variable has been assigned a value, i.e. is set? unset ...
1
vote
2answers
34 views

Does command substitution create a subshell?

Bash manual says: Command substitution, commands grouped with parentheses, and asynchronous commands are invoked in a subshell environment that is a duplicate of the shell environment, except ...
0
votes
1answer
24 views

Convert a column of epochs into a time column starting from 0

What I have Hi, imagine a lot of this files, where first column is epoch, and the other(s) column(s) are some data: 1000333,34,1 1001456,56,0 1005356,34,2 What I need I need to transform them ...
0
votes
1answer
9 views

Trouble using if string in column 3 of .csv exist, then statement

I have a set of 10 files. 5 are unique tumors tissues and the other 5 are matching normal tissues… So {tumor_A, normal_A, tumor_B, normal_B,… tumor_E, normal_E} These files each have a random ID, ...
0
votes
1answer
11 views

Centralising Discs to Repository?

I have discs where is much variations. I would like to add the files to my central repository. However, I am getting warnings about ownership. I am thinking of running sudo chown -R masi:masi ...
0
votes
3answers
23 views

Backup script fails with the rsync command's options in a quoted variable

Using: rsync version 3.1.0 protocol version 31; Linux Mint 17 (based on: Ubuntu 14.04.3) In one of my backup Bash scripts, which uses rsync, I put the rsync options in a variable like this: # Set ...
1
vote
2answers
19 views

Unexpected field expansion behavior by bash for loop

I am having a problem reconciling all of the field expansions rules in linux/unix, so I've been experimenting. Here is an example which based on my reading is not consistent with what I'd expect. ~$ ...
1
vote
3answers
26 views

How to determine callee function name in a script

to make it short, doing s.th. like -bash$ function tt { echo $0; } -bash$ tt yes, $0 will return -bash BUT how to get the function name called, i.e. tt in this example instead?
1
vote
1answer
31 views

Remove a part of a path from a variable content

In a Bash I have a variable: LOCAL_PATH="/this/is/a/path/" Then I have another variable, which content starts with LOCAL_PATH and it should be removed: LINE="/this/is/a/path/which/is/longer" The ...
1
vote
2answers
86 views

What do you use when you can't use Bash? [on hold]

I am trying to make a shell script that runs on a widest variety of *nix systems. So, if I wrote a bash script backwards compatible with old versions of the shell, but what if bash wasn't on the ...
0
votes
2answers
30 views

Check if a file contains a certain pattern?

#!/usr/bin/expect -f ps ps -ef > test.txt Now if I want to check whether test.txt has certain keywords present, in it, how do we go about? say: 'apache' or 'fast' Can we use the if statement ...
3
votes
1answer
23 views

grep output of cdrecord

I would like to parse the output of cdrecord/wodim using grep. cdrecord -v outputs lines like Track 01: 49 of 75 MB written (fifo 100%) [buf 100%] 10.2x. The problem is that cdrecord uses ...
-4
votes
1answer
36 views

Simple bash script to print prime numbers from 1 to 1000 [on hold]

How can I make a POSIX script that will print all the prime numbers from 1 to 1000? Lots of thanks
3
votes
3answers
346 views

How can I use '*' to capture everything with exceptions

For example, I have files named A_1.txt A_t_1.txt A_ts_1.txt A_tsa_1.txt in a directory ~/admin/packages/. I am building a for loop to by globbing to A_1.txt for f in ~/admin/packages/*_1.txt ...
0
votes
2answers
36 views

Bash - Redirect output to a variable or file descriptor, then read from the variable or file descriptor

Here's an example of a bash script that redirects all output to a file (and shows output on the screen too): # writing to it exec > >(tee --ignore-interrupts ./log) exec 2>&1 echo "here ...
0
votes
0answers
22 views

Include text from other file in screen printf

The original code of main.sh: screen -S myscreenname -p 0 -X stuff "`printf "myabcdefg"`" I want to put only abcdefg (without my) in other file. Below codes works just fine but I need the text.txt ...
2
votes
4answers
45 views

how to access the next argument of command line parameters in bash?

Say I have the following: for i in $@; do echo ${i+1} done and I run this on shell $ test.sh 3 5 8 4, it outputs 1 1 1 1 why wouldn't ${i+1} work? I am trying to access the next argument for a ...
1
vote
2answers
25 views

Should the operands to a utility always appear after all the options to the utility?

POSIX says utility_name[-a][-b][-c option_argument] [-d|-e][-f[option_argument]][operand...] ... The arguments following the last options and option-arguments are named "operands". ...
0
votes
2answers
58 views

How is a command following the while command executed over the loops?

In while <command> part of a while loop, is <command> executed in each loop independently of other loops? In the following example, why can the while loop make read read all the lines of ...
0
votes
2answers
35 views

Command to skip process if file exists

I have been using a for loop to run a pipeline for multiple files but unfortunately the terminal froze halfway. I would like to run the pipeline again but because of time I would like to skip the ...
1
vote
1answer
37 views

How do I maintain sudo in a bash script?

If I run this script, how do I pass super user permissions to it? I wrote this just to setup new machines with the basics. I don't want to run every command with elevated permissions, but the commands ...
0
votes
1answer
16 views

Help designing an 'extract - store - feed' workflow

Working with a large volume of files, I would like to automate the process of storing stdout info as a variable that I can feed into as an input for my next process. Specifically, when I put... ...
0
votes
2answers
25 views

How to change the first column of data in a file?

I have .data file containing a table of numbers with the column format: m x y z vx vy vz separated by tabs, with a depth of 2000. The file name is initc.data. I want to change ...
0
votes
3answers
34 views

Can I compare the parameter of a script to an array of variables and process it?

I want to manipulate the expanded value of a variable that has been selected from an array after user input. Here's what I mean: $ ./myscript.sh url2 #!/bin/bash array=(Sigil wp2epub csskit) ...
-2
votes
0answers
38 views

Script for logging in to multiple servers and running some commands [on hold]

I have a list of host/server names in a text file. I want to log in to each host using SSH and run certain commands. I'm using password authentication. When ssh'ing to another server, how to handle ...
0
votes
1answer
33 views

Exporting a Variable from bash script does not work, does work if I change the variable to any other name [on hold]

This is the strangest behaviour I have ever seen. I know you might be shocked to see the below explaination but yes this is happening. I'm trying to export a variable name which is LON_GEMINI_BOX ...
-1
votes
0answers
31 views

How to execute command with sleep and log its output and service ID [on hold]

I am executing ( sleep 0.1m; sudo send 11111 2 1 ) 2>&1 & command from php this how: $command = '( sleep '.$delay.'m ; sudo send '.$switch->code.' '.$switch->number.' ...
0
votes
1answer
32 views

Read columns from file into separate variables

I need to read the following input into separate columns as variables? input.txt b73_chr10 w22_chr9 w22_chr7 w22_chr10 w22_chr8 w22_chr6 I have written the following command;but I guess it ...
-2
votes
1answer
29 views

Read columns from file and substitute values in another file using bash script [on hold]

I have following file : input.txt b73_chr10 w22_chr9 w22_chr7 w22_chr10 w22_chr8 w22_chr8 I have written the following code(given below) to read the first and second column and substitute ...
8
votes
2answers
292 views

Bash .hushlogin, keep last login time and host

At my company, when I log into some servers, my last login and a huge banner are displayed: me@my-laptop$ ssh the-server Last login: Mon Feb 8 18:54:36 2016 from my-laptop.company.com ...
0
votes
2answers
21 views

Bash 4, expansion and putting to lowercase

I see that in Bash > 4.0 variable expansion is used to lowercase a variable. For example echo ${variable,,} Reading the man page I really don't get why the shell is converting the string to ...
-1
votes
2answers
42 views

how to login a user using shell script [on hold]

In my computer i have two user(tiger,jenk) now i want to create a shell script for login user "jenk" from user "tiger" i m try this code [tiger@pagaltiger mytask]$ echo -e "IncorrectPassword\n" | ...
1
vote
3answers
35 views

Run a command over directories with name recursively

I have the following directory structure in AIX. codeRepo/REPO1/AREA1/objects codeRepo/REPO1/AREA2/SUBAREA1/objects codeRepo/REPO1/AREA2/SUBAREA2/objects From codeRepo I want to run chown myUser * ...
0
votes
2answers
27 views

Exec vs source error on ==

I run a strange error with the following code: #!/usr/bin/env bash a="a" b="a" if [ "$a" == "$b" ] then echo "Eq" fi chmod u+x script.sh Then executing the file will display Eq: $ ./script.sh ...
2
votes
2answers
45 views

How to ensure echo into a file has been flushed? [on hold]

I have two co-operating programs X and Y running on the same system. X some times uses Y to calculate some information. I use file based communication between the programs. When X wants Y to compute ...
1
vote
1answer
39 views

How do you list number of lines of every file in a directory in human readable format.

I have a list of directories and subdirectories that contain large csv files. There are about 500 million lines in these files, each is a record. I would like to know How many lines are in each ...
1
vote
2answers
24 views

How do you list all functions and aliases in a specific script?

I have a bash script that's getting quite long. It would be nice if I could list all the functions in it. Even better would be listing the name of the function and any documentation about it's ...
0
votes
3answers
65 views

To calculate average by taking command line argument

The task is that if input numbers: 4 1 2 9 8 Output=(sum of all except first_number_in_series)/first_number in series Then output average should be 1+2+9+8/(first_number_in series)=20/4=5 I have ...
0
votes
1answer
14 views

How does a Zenity progress dialog's cancel button function?

While trying to make the Cancel button on a Zenity --progress window work for my scripts I've realized I don't understand how the Cancel button works at all in the example given on the Zenity Manual ...
0
votes
2answers
30 views

How do I search a directory of data files and print out how many times a certain word appears in each file?

This is what I currently have, however it prints the total number of times Author appears in all of the files: 128367 grep -roh 'Author' $1 | wc -w However how do I print out the word count for ...
0
votes
1answer
55 views

How do I inform the rest of the system my shell has changed from zsh to bash?

I installed zsh because I thought I might prefer it over bash. I don't, and to revert it I have used chsh -s /bin/bash, which as myself gives You may not change the shell for 'cat'. I also changed ...
-2
votes
1answer
44 views

KSH for generating 'n' of rows for a table dynamically : Issue with if else statement

I need to generate billion of records in a text file for table loading purpose. My destination table defination is: CREATE TABLE txnrecords12( txnno int, txndate string, custno int, ...
1
vote
1answer
48 views

Using -n option with pushd and popd

popd Remove the top entry from the directory stack, and cd to the new top directory. When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top ...
-1
votes
2answers
66 views

How to delete all the lines in a UNIX file except first and last line? [on hold]

I want to keep only header and trailer records in a UNIX file.
0
votes
0answers
11 views

SIPS changing padcolor to transparent in landscape

I am creating a bash script to automate the scale down and padding of a lot of images. The idea is this: whatever the image size is, if the image is portrait, scale the height to 960 and add a white ...
0
votes
3answers
41 views

Why does (` `) gives a list and $() gives only one argument

I might not word this properly, pls edit. Say I have: lst=(`ls $1`) echo $lst #this gives the first element of the list but then when I tried this: lst=$(ls $1) echo $lst #this gives me all the ...
1
vote
3answers
51 views

Find size of file in unix using for loop

I am trying to get the size of each file in a directory using a for loop, running the below script #!/bin/bash FILE=/home/cloudera/Desktop/new for file in $FILE do size=`du -b ${file} | cut ...
0
votes
2answers
13 views

Using Screens with a PHP Script

I found an external developer to make me a PHP script to 'snipe' Mineraft usernames. In order for it to operate, I have to start the script from the command line using this: php -f sniper.php > ...