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)

2
votes
2answers
45 views

for loop to iterate through some file nth position

How do I iterate for nth file in a for loop in unix? below some code I have tried but not succeeded #!/bin/bash # n=2 array=( "CTL_MLPOSDTLP1_1.ctl" "CTL_MLPOSDTLP1_2.ctl" "CTL_MLPOSDTLP1_3.ctl" ) ...
0
votes
1answer
34 views

Check for subdirectory

A)I used the following code to get the modified date of a file. But this is also selecting the subdirectories and thus returning an error. How van I fix this. for file in $1/*; do echo `stat ...
1
vote
4answers
117 views

How to subtract two times in shell

I nee to subtract two lines which is in the format of time in shell. Th time format is hh:mm:ss I used the code below to get the time. cat /var/log/kern.log |grep usb |tail -2| awk '{print $3}' The ...
0
votes
1answer
28 views

elif command is throwing error [closed]

Hi is the below elif command correct? elif [[ "${FILECOMMAND}" = "" ] && [[ -f ${ZIPFILE} ]||[ -f ${ZIPFILE3} ]]] I am getting an error when I run it.
0
votes
2answers
41 views

How can I redirect the same message to both stdoud and stderr (without temporary object)

It is easy to redirect stdout or stderr to the same output (file or one of the 2 std output) with a 1>&1,>&2 and/or >file. Is there a way to send the same output to both the std ...
2
votes
2answers
93 views

How to show only total file size of particular extension by `du` command

I have a hundreds of pdf files and html files in a directory. And I want to know total size of pdf files. By command du -ch /var/foo I can see total file size but I only need last line, the total ...
1
vote
1answer
126 views

Adding multiple user with shell script on Ubuntu

Can someone help me in providing me the shell script for creating multiple users on Ubuntu. Password needs to be different for each user. Thanks in advance
1
vote
2answers
43 views

Shell, howto extract letters from $line1=“Test this… test this!”, and print one by one

I am writing a script, which I would like to spice up a bit. What I need, is a loop, which takes one letter at a time, including space, and then write it on the screen, like an old typewriter would ...
2
votes
1answer
50 views

PS1 prompt showing different on local and remote console

This is my PS1 prompt: export PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;35m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ " That shows perfect in remote (SSH) ...
0
votes
1answer
44 views

Why can't my `date` deal with timezones? [duplicate]

I'm having some weird issues with GNU coreutils date v8.4 (CentOS) that aren't occurring in v8.21 (Ubuntu/Mint). On v8.4, I get the following output (I'm in PST): $ date --version | head -n 1 date ...
0
votes
1answer
31 views

Trying to make aliases that open the last modified file

One thing that I frequently do is edit the most recently modified files, so instead of typing "ls -lr" and then "vim lastfile", I thought I would make some shortcuts in my ~/.bash_profile file: alias ...
3
votes
2answers
66 views

Syntax error: word unexpected on io redirection on file descriptor ≥10

I have the following shell script on debian 7: #!/bin/sh case "$IFACE" in lo) # The loopback interface does not count. # only run when some other interface comes up exit ...
0
votes
0answers
19 views

How to check if a shell is interactive or not for Bourne shell [duplicate]

How can I test with a command/condition if I am in an interactive (ran by user) or a batch (ran by a cron job) Bourne shell (not Bash)?
0
votes
1answer
25 views

Pre-process 1 single option

I've got a Shell script (intended for Linux/Mac/Cygwin users) that wraps an executable JAR. Before passing the arguments (long or short form) to the Java program, I need to pre-process one single ...
2
votes
5answers
110 views

How to find different files in UNIX based on . extension?

How to find different files in UNIX based extension. Lets say suppose if I have 100 files for each vamsi.log-vamsi100.log, krishna.txt-krishna100.txt, super.csv..., rajat.jpeg..., ...
0
votes
2answers
69 views

cat STDIN won't work twice in script

I have a script that outputs various information and the text fields of an html form (method POST). When I attempt to cat <&0, it displays properly. However a few lines down, I try to cat ...
1
vote
1answer
35 views

For loop for curling on multiple pages with API's

I am trying to crawl a website for fetching pages using an API. When I issue the command cd desktop/mysite ; curl -O https://api.mysite.com/info?page=2 I get the data on the desktop. Then I wanted ...
1
vote
1answer
52 views

how do I remove ./ from the file name

How do I remove ./ from the file name ./script 1 when entering it as a command. I want to be able to enter the command just as script 1 for it to run?
2
votes
1answer
24 views

`top` not refreshing screen on exit

When I exit top, the prompt reappears at the bottom and I can see the bottom of the last thing it was showing. How can I get top to behave like less i.e. refresh the screen back to when I launched ...
2
votes
1answer
19 views

Check which RPMs depend on this package

I want to get a list of packages which depend on requested package. For example, I want to get all packages, which depend on telnet. I came up with this script: for i in `rpm -qa | sort`; do rpm ...
0
votes
1answer
32 views

Background a process and execute something with one command

Probably it would be easier to do just with a script, but I wonder why can't I do that with one command. What I have tried so far: $ (ls >/dev/null &) && echo $! 3135 $ (ls ...
4
votes
2answers
123 views

Can multiple mv commands be run in the same directory (race condition)?

I'm moving a large number of files (400K+) from one directory to another and I have the following script to do so (too many files for the mv command to work directly): for file in *; do mv $file ...
1
vote
1answer
57 views

How to restart my server automatically using crontab if they went down?

I have a jar file which I am running like this in my Ubuntu 10.10 and then it starts my exhibitor server in the background - nohup java \ -jar ...
3
votes
1answer
22 views

I need to create file with name is the result of the command in Solaris

I need to create only one file with name is the result of the command ls -l | head -2. I can't use environment variables. The filename must contain newline symbols. I've tried to use touch 'ls -l | ...
0
votes
2answers
32 views

How to launch «gdbserver» in background?

I am communicating with a device via a serial port, and for I am launched «gdbserver» (like gdbserver :2345 myapp) it completely blocks the terminal. Neither an ampersand & symbol, nor ^z ...
0
votes
4answers
273 views

keep the last file of every month and delete the rest

I have files like below. I want to keep SEP 30, OCT 30....files and delete the rest. Can you please help me with any script? -rw-r--r-- 1 nbswmcm advboprd 13463761 Sep 2 01:19 ...
3
votes
4answers
295 views

Which directory is taking up the most space

Jenkins has stopped building and I can see from df: that /var is maxed. Following this I can see the culprit is /var/lib/jenkins 52K alternatives ... 4.0K games 2.3G jenkins <--this ...
0
votes
1answer
59 views

Shell string escape for command arguments [duplicate]

I'm trying to create "/tmp/pwet/foo bar" with this: DIR="/tmp/pwet/foo bar" ARGS="-p ${DIR}" mkdir $ARGS For integration reasons, I have to keep the ARGS building in 2 steps: ARG = some_options + ...
0
votes
2answers
39 views

can I use logical operators to remove all files that matches with one and/or other pattern in a single line?

I want to remove .txt or .csv files in a single line. What I have in my directory tachomi$ ls file1.csv file1.sql file1.txt file2.csv file2.sql file2.txt I only want .sql files so I want to ...
3
votes
2answers
44 views

echoing basename under xargs?

I have the following command : ls /some/path/*dat | xargs -n 1 -I @ sh -c "echo `basename @`" with the directory /some/path/ containing : /some/path/a /some/path/b /some/path/c /some/path/d I ...
2
votes
1answer
73 views

grep of a shell variable finds nothing

I have some problem with grep. I wrote a script which need to find some numbers from a list (file name ContigsNames) in a database. I wrote the following script: file=ContigsNames while IFS=' ' read ...
1
vote
0answers
79 views

Cannot add startup service to openWRT from init.d

I have openWrt installed on a TP-Link TL-WA901N/ND v3. I don't have luci package installed because I don't have enough space, so I can only do thing via cli. What I'm trying to achieve is to create a ...
-1
votes
3answers
59 views

what is the use of '<<' redirection? [duplicate]

I am looking for an example of << redirection because i don't understand it well. I know < is for sending the contents of specified file to be use as standard input like : cat < file.txt ...
2
votes
1answer
172 views

Shell script, find -name, and wildcard expansion

I'm trying to use find -name in a sh script with a previously computed complex argument for the condition. Simplified, it goes like cond="-name '*.txt*" find . $cond -ls But now I have the problem ...
2
votes
1answer
32 views

Problem with install command to copy a whole directory

So I have a repo with some of my config files and I'm trying to create a makefile to install them in the homedir. The problem I have is that when I run the following command straight in bash install ...
2
votes
1answer
27 views

Strange leading whitespace in OPTARG when using getopts

I spent quite a while researching the problem I encountered but none of the getopts tutorial say anything about the leading whitespace in OPTARG when using getopts. In bash(on Ubuntu and OSX), ...
2
votes
2answers
45 views

Global Shell Variables?

As a system administrator with root access on a unix machine, is it possible to provide default shell variables to all users of a system? That is, as an individual unix user, I can define ...
1
vote
1answer
56 views

“Pipe” command to new bash shell?

I want to add my private key to the ssh-agent and I'm following these instructions. According to this the command ssh-agent bash spawns a ssh-agent bash and I can add my key afterwards using ...
1
vote
2answers
58 views

How to convert time from local timezone into Sydney timezone using korn shell?

I need to convert time from localtimezone (CET/CEST) to Sydney timezone (AEDT/AEST). I tried something like this: export date=$(date "+%Y-%m-%d %H:%M:%S AEDT") date "+%Y-%m-%d %H:%M:%S %Z" -d "$date" ...
0
votes
1answer
74 views

Unix shell script for server alerts

Below is my shell script which is written in another x to find the health of server y. ( I have not written in server y because there is no functionality of getting mails) #!/bin/bash ...
0
votes
0answers
70 views

Why isn't this `expr … | bc -l` command working?

I'm noticing an error: bash: syntax error near unexpected token `-105.5*7+50*3' When executing the below script/expression: expr (-105.5*7+50*3)/20 + (19^2)/7 | bc -l Is there any other way ...
3
votes
7answers
227 views

get parts of string using shell script

I have one string as /ip/192.168.0.1/port/8080/ I want to get two separate variables which will contain port and IP like. 192.168.0.1 and 8080 as I know /ip/ and /port/ will be there always I ...
1
vote
1answer
47 views

Installing packages on multiple Centos machines

I have to install standard package like java 1.7 in 40 of my lab machines which are connected over a LAN. I know I can simply write a shell script to install something in user space of each system, ...
4
votes
3answers
91 views

Arithmetic operations with expr and variables

Why won't this statement work? total=`expr $mPercent / 100 "*" .482 + $fPercent / 100 "*" .518` mPercent is a number as a result of an awk statement, as well as fPercent. I also get "expr: ...
0
votes
1answer
52 views

How can a script ask me questions?

I am using this script to analyse data: #!/bin/bash in=/autofs/cluster/transcend/mega/scripts/ insub=/autofs/cluster/transcend/mega/dtn/20141015/123 out=/autofs/cluster/transcend/mega/scripts/1256 ...
3
votes
5answers
127 views

List files with line count and date

I want to be able to list files showing the number of lines the each file has and the date. I can happily get the line count using wc -l *. Not a problem. I can get the date using ls -l. Is there a ...
1
vote
2answers
65 views

Combination of echo, pipe and cat

I have a file name called temp.csv in my script one of the intermediate step is echo "some info" > final.csv | cat temp.csv >> final.csv at times the file final.csv is created without ...
14
votes
4answers
2k views

What does echo $-1 display?

What does the output of echo $-1, echo $-2, echo $-3.. mean? On one of my Linux boxes, it shows me: echo $-1 imsBEl1 echo $-2 imsBEl2 And on another Linux box, it shows: echo $-1 himBH1 echo $-2 ...
1
vote
1answer
125 views

Jenkins does not use system's locales

I got a interesting behavior in Jenkins. Jenkins' shell does not use my systems locales. Jenkins runs as user jenkins on my system. Logged in as jenkins via SSH: locale displayed: ...
5
votes
2answers
424 views

How to treat strings with spaces as a whole in bash? [duplicate]

I'd like to build an error handler which will make an empty file marked with the error_occur time. The core idea is to use the result of date command as a parameter. I did: time_stamp=$(date) touch ...