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
26 views

Adding “ubuntu” user to Vagrant ubuntu instance

I am using a vagrant box : uname -a Linux precise64 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 x86_64 x86_64 It does not have ubuntu user setup , instead it has vagrant one ,so I ...
2
votes
1answer
36 views

GDB cannot exec my test program

My computer run with Ubuntu 14.04. GDB seems to be abnormal in different account. For example I make a very simple test. I write a file under ~/test/test.c like this: #include <stdio.h> ...
0
votes
2answers
46 views

Bash getting integer expression expected

I have following script to check disk usage #!/bin/bash # set alert level 90% is default ALERT=10 OIFS=$IFS IFS=',' storage=$(df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " ...
4
votes
1answer
76 views

Executing a “fork bomb” safely

We've all seen the "fork bomb" that will render a host non-responsive, even if executed in an unprivileged shell: Warning: Do not execute the following shell script. Just don't. :(){ :|:& };: ...
0
votes
4answers
40 views

Print only directories with more than 31 files

I am using this script to count files on my directory and sub-directories: for i in $(find . -type d) ; do printf "$i %s\t" ; ( find $i -type f | wc -l ) ; done This script works fine. What I ...
2
votes
2answers
40 views

Tar a list of files which don't all exist

I'm running a command from a script like tar -c -f ar.tar a b c d where b, c, and d may not exist, and may be directories. The solutions that I've come up with are piping the output of ls -d to ...
1
vote
1answer
36 views

How portable is this shell assignment?

VAR=${VAR:-value} The purpose is to set the environment variable VAR to value unless it's already set. I see it works in bash and dash, but how portable is it?
3
votes
4answers
190 views

what is the difference between `find .` and /home/user/* as an input to for command

What is the difference between find . and /home/user/* as an input to for command.? For example: for var in $(find .) do echo "$var" done or for var in /home/user/* do echo "$var" done In the ...
2
votes
1answer
20 views

Append same timestamp to multiple filenames

I have several files that I ftp each hour. The receiving system needs to have some sort of identifier that they came from the same batch, so I would like to append a timestamp to the filename. That ...
2
votes
2answers
81 views

Typing text from a shell script [duplicate]

I'm new to shell scripting. I'd like to know if there's a command similar to "echo" for displaying text in a terminal, but instead of simply displaying it immediately, it actually types it, like if ...
0
votes
1answer
13 views

Loop across url with static tokens with Oauth

I need to write a loop where I need to pass a "token" (which is fixed) and a variable (i) in the url. Is there any way I can achieve that? I wrote the following code but it is not working. If I put ...
5
votes
3answers
269 views

How to view last 5 lines from last created/modified file?

Every day I have to take backup and update the status to support teams at particular time for which I need to check last 5 lines of last created/modified *.aff file in a directory and update them. ...
2
votes
2answers
31 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
27 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
98 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
27 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
33 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
57 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
50 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
41 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
44 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
38 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
24 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
49 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
23 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
97 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
45 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
30 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
21 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 ...
1
vote
1answer
10 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
25 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
96 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
48 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
27 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
245 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
259 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
49 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
35 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
36 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
67 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
40 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
53 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
130 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
27 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
26 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), ...
-1
votes
0answers
30 views

Empty terminal window - ZSH does not start? Can't use terminal

I have a chromebook pixel running Manjaro. Up until about 10 minutes ago, this machine was running great. I'd been using the terminal emulator (terminator) all day, when I tried opening a new shell ...
2
votes
2answers
43 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 ...