The shell is unix's command-line interface. You can type commands in a shell interactively, or write scripts to automate tasks. Use this tag for questions applying to /bin/sh and most compatible shells (ash, bash, ksh, zsh, …).

learn more… | top users | synonyms (1)

1
vote
1answer
67 views

Convert vertical array data to horizontal array data

I have a file with 25 matrices in a file, and each matrix is has 128 rows and 5 columns. Each matrix are putted one after the other, in a vertical way. Like this File input(file1): Array1 Array2 ...
2
votes
2answers
65 views

What is the best way to unlink hard-linked files?

Using rdfind I found a lot of hard-linked files (~60-90) and I want to unlink all of them. One possible solution is to just find all files -link +1 and just copy them, delete them and move it back to ...
2
votes
2answers
88 views

Use env with environment variables from file

Let's say I have a file (called e) with this content: a=3 b="5 6" How can I get each one to be interpreted as a separate argument to env? That is, to have it equivalent to: $ env a=3 b="5 6" ...
1
vote
1answer
44 views

Spawn command not found

I trying to use the spawn command to connect to remote server, execute some commands/script. Here is script: #!/usr/bin/expect for i in `srvctl status database -d PROD | awk -F " " '{print $(NF)}'` ...
1
vote
1answer
26 views

Group or world writable directory

I'm trying to use a script but get the following error: Directory is group or world writeable. This is insecure, since any malicious user can trick you to write newly generated private key into his ...
0
votes
2answers
48 views

How to fetch all the even lines and odd lines from a file and save them into two different files such as Evenfile & Oddfile? [duplicate]

The question is very simple. Suppose I've a file named "a.txt" and it has 100 lines. Now I want to extract odd lines i.e lines 1,3,5...etc and save them to a different file such as Odd.txt and the ...
0
votes
1answer
63 views

Weird user in shell

I use iTerm on OS X 10.10 When I start iTerm I get the weird user unknownA988274AC:~ myUserName$: That was not there before. Before there was myUserName$: Any ideas where that comes from?!
4
votes
4answers
44 views

Running multiple programs in the background and checking their return value

suppose I want to run a few (say, three) programs at once, like this program1 & program2 & program3 & if I want to know their pid's, I think the best way is to store them, like this ...
2
votes
2answers
70 views

Is there a way to route all commands through a shell script instead of running directly?

Sorry about the title, I can't explain it very well without an example. I want to be able to have everything being executed, rather than running the program, runs a shell script with the executable as ...
1
vote
1answer
37 views

cd to previous directories [duplicate]

I'm running CentOS 7, but hoping there is a general Linux way of doing this. So you can cd back and forth between the previous and current directory with this: cd - Is there I way can cd back ...
0
votes
2answers
116 views

How do I print 'block' letters in the terminal?

How do I echo/print block lettering in the terminal like: ? figlet and toilet don't help. Neither do U+25A0 or U+2588 unicode characters. This is not a duplicate. As I said, figlet, banner and ...
0
votes
0answers
30 views

Significance of shell script with XML

I have recently joined anew project and experienced the structure where Shell scripts are usually directed to a target which is set in XML and that XML containing action in the tags which needs to be ...
1
vote
2answers
65 views

How to make sure that a child process of a supervisor job dies when I kill supervisor

My app is a jar file that requires some environment variables. I have all the environment variables in one file, which looks like this: export VAR=value export VAR2=value2 #....etc My supervisor ...
5
votes
3answers
489 views

Exclamation mark variable `$!`

I have been studying for my Unix exam and I often saw exclamation mark variable - $! If I write echo $! on my Mac shell tells me something like "You have mail in…" Is purpose of this to store whether ...
1
vote
3answers
52 views

Variable assignment syntax error in shell [closed]

VALUE=${VAR| |o} I found this variable assignment in shell script. I can't understand why || sign is used here. EDIT Code given in a comment: #!/bin/bash source /opt/cpf/bin/cpf_logging_helper.sh ...
1
vote
1answer
69 views

Bash Function Parameters - Spaces in Filename [duplicate]

I know there are rules for quoting parameters, but no matter what I try, I can't seem to figure out how to make this work. I have a function that takes a single filename as a parameter, then uses ...
-2
votes
0answers
19 views

Merge records in a pipe delimited files when first column value is same, based on the date field in the file

Sample File Input: CustomerKey|EmailAddress|storeID|preferenceCd1|preferenceCd2|preferenceCd3|preferenceCd4|preferenceCd5|modifiedSystem|modifiedDate 1006374|meeb12@test.com||2R05||||||2015-03-18 06:...
2
votes
1answer
44 views

Accessing random array element in ZSH

I have ZSH as my primary shell, and I'm trying to randomise access to an array. I keep seeing feh called, but I don't have that command. I have _feh, but I don't know if it's the same thing. What is ...
52
votes
10answers
4k views

Use of touch and vi?

Is there a benefit of creating a file with touch prior to edit.. like: touch foo vi foo versus getting it to editor straight-away? Like: vi foo I see quite a few tutorials using the former (...
1
vote
1answer
26 views

when the cron job start after installing new crontab?

I need to a crontab execute each 12 hours, so I have the following: 0 */12 * * * . /X.sh then Linux is installing new crontab. after that, I am waiting for 2 hours and still the cron job didn't ...
4
votes
3answers
355 views

Executing of all shell scripts in a directory starting with the letter 'a'

I have many shell scripts in a directory starting with letter 'a'. How could I execute all of those shell scripts at a shot? Can we develop any other small script to run this?
0
votes
2answers
55 views

To include double quotes within a string

My command is X=`ssh ${OS_USER}@${OS_HOST} ". ~/.kshrc ; ulimit -c unlimited ; cd ${OS_PATH}/NEW_BL1_RC_RATE/bin/conf; echo "export RC_DB_INSTANCE=$7" >> RC_CONV_SET_VARS"` $7 should ...
-1
votes
0answers
22 views

Loading configuration via putty

I have a NVR hybrid system that runs off of linux. Is there a way I could load a configuration file into this NVR via putty? Basically the file would be a snapshot of a finished NVR with the ntp set ...
0
votes
1answer
22 views

Redircting stdout to file, but duplicating stderr to both file and terminal [duplicate]

Redirecting stderr to file and duplicating stdout to both file and terminal is easy: $ prog 2>error.log | tee output.log tee will duplicate stdout, printing it to both terminal and output.log. ...
7
votes
4answers
128 views

How do I determine if a program is running when I start a shell and start that program if it is not already running?

When I start a shell, in my case bash and/or zsh, what lines do I need to add to .zshrc and/or .bashrc to check to see if a program is already running, and if the program is not already running, start ...
12
votes
3answers
873 views

How to remove \n between the outputs of two echo commands?

I have a text file containing one file name in each line: 111_c4l5r120.png 123_c4l4r60.png 135_c4l4r180.png 147_c4l3r60.png 15_c4l1r120.png ... I want to convert it in this shape: 111_c4l5r120.png ...
2
votes
2answers
65 views

how can I find files based on different names and delete all them in one single line [duplicate]

Finding files based on different names I know how to do. The problem is that I don't know how delete all of them at once. I am using OMVS in z/OS390. To find files searching by different extensions I ...
-1
votes
2answers
164 views

How to sum many numbers inside 2D array using awk

I need to sum numbers located in a file like this one: column1 column2 column3 row1 a(1,1) a(1,2) a(1,3) row2 a(2,1) a(2,2) a(2,3) row3 a(3,1) a(3,2) a(3,3) row4 a(4,1) ...
0
votes
2answers
49 views

Switch case not working in Shell

I am new to shell and am intending to use gdialog to take user input and feed it to switch case in shell. Below is my code: #!/bin/sh which gdialog 2> /dev/null && DIALOG=gdialog || ...
-1
votes
0answers
30 views

awk used for duplicate is failing while recreating same file [duplicate]

When i am running command below its just vanishing the complete data from the appirx.txt. Can any one explain the mechanism behind it.It might be basic question awk '!seen[$0]++' appirx.txt > appirx....
3
votes
1answer
63 views

How variables inside braces are evaluated

I'm new to shell scripting and I came across these expressions ${var:-val} and ${var-val} ${var:+val} and ${var+val} ${var:=val} and ${var=val} so how are they evaluated and what are the ...
1
vote
0answers
23 views

find-like tool to search (recursively) in MailDir folders by size, sender, recipient, attachment name regex, etc

I am not looking for a tool like locate, that works by creating an index in the MailDir, or generating other runtime files there; I am searching for real-time, direct search on live MailDirs. The ...
0
votes
1answer
41 views

Shell prompt displays .f>

I am running SSH through this command: ssh <machine-name> But instead of seeing the machine name in the prompt, I see .f>. Normally the prompt looks something like machinename> Any ...
10
votes
4answers
370 views

Run command after a certain length of time has elapsed?

If I'm executing a long process, is there any way I can execute some time-based commands? For example, I'm running a really long process which runs for roughly 10 minutes. After 5 minutes, I would ...
3
votes
1answer
20 views

Start new process group in .xinitrc

I have a statusbar (lemonbar) to which I pipe the output of a couple of scripts (time, battery, volume, etc.). These scripts, and the statusbar itself, are all started in a single bash script ...
2
votes
1answer
40 views

Get DISPLAY value by username

I run following commands to get DISPLAY value for a logged in user. $ loginctl list-sessions SESSION UID USER SEAT c2 1000 asif seat0 ...
3
votes
1answer
47 views

Shell syntax for redirecting arguments?

If I want to redirect not the stdio but as arguments the output of a program , should I use xargs? For example, I do ls and I want the filenames to be arguments to the next command rather than an ...
1
vote
1answer
42 views

Move files several directories up for several directories with similar layout

I have a directory with the following layout (the layout in Directory 1 is repeated in every other Directory <num>): Parent directory Directory 1 some directory another ...
1
vote
3answers
44 views

how to spawn a separate process in the background while running a foreground process

e.g., I want run a python -m HTTPSimpleServer in the background while running a watch in the background python -m HTTPSimpleServer; watch -n (my awesome test command) how can I run both in ...
2
votes
1answer
58 views

on-line tally of unique lines

uniq -c is very useful for counting the number of times the same line appears consecutively $ seq 1 1000 | awk '{ if ($1 > 100 && $1 <= 200) { print "hi" } else {print "bye"} }' | uniq -...
2
votes
4answers
52 views

Access a file located with find

In many cases after I find a file using the find command I then want to open the file or cat it or maybe print it. How can I operate on the result from find? For example, : find . -name "myfile.txt" ...
2
votes
2answers
108 views

what is the difference between “./command” and “bash command”

I have simple bash script file, it contains only one line: rvm gemset use --create 2.0.0@PRJ_NAME If I run this script with: ./scriptname.sh I get a well-known error message from RVM RVM is not ...
0
votes
1answer
48 views

How to merge or join more than 2 files? [duplicate]

I have four files; file1: gene_id FPKM TRINITY_DN56960_c4_g1 36.91 TRINITY_DN42427_c0_g1 12.83 TRINITY_DN48728_c0_g1 6.22 TRINITY_DN50706_c0_g2 6604.75 TRINITY_DN51449_c1_g1 8.19 ...
1
vote
2answers
52 views

Use variables in here-string

To feed input to an interactive script, I've been using a here-string: script <<< $'1 2\n3 4\n5 6\nq' This effectively enters 1 2 3 4 5 6 q into the script. But how can I replace one of ...
1
vote
2answers
20 views

Get owner / user of a cronjob

In Linux (Mint / Ubuntu), I can create cronjobs for each user individually. Is there any way, I can find out the name of the user against whome the cronjob is running. I want to get the username of ...
1
vote
2answers
46 views

A quicker way to change owner/group recursively? [duplicate]

Currently, when I want to change owner/group recursively, I do this: find . -type f -exec chown <owner>.<group> {} \; find . -type d -exec chown <owner>.<group> {} \; But ...
-1
votes
0answers
39 views

How to write the shell script which check if the file is present on the cluster file system?

Suppose we have pscp on Windows, and remote control to Linux cluster through key key.ppk, the user and host is name@cluster.com. How, by using shell script (in cmd file), check if some file is present ...
0
votes
2answers
41 views

Shell Script to insert lines in between file

Suppose there is one file1.txt where content is written Ramesh Suresh Raman From the below shell script ,I am reading the content name from file1 .txt and preparing the Name=$line in echo statement....
3
votes
4answers
133 views

Where should I save color codes for the PS1 command line / terminal? [closed]

This question is about best practices. I know logging in over secure shell or switching users su, and su -l have different effects. Also, in the event you make a typo in the configuration, you still ...
0
votes
0answers
66 views

Send command to open process in Shell file

In bash how can I issue a command to a running process I just started? For example; # Start Bluez gatttool then Connect to bluetooth device gatttool -b $MAC -I connect # send 'connect' to the ...