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

Verify the length of a variable

I've to verify the length of variable read (my script limit to five the characters inserted), I think about something like this: #!/bin/bash read string check=${#string} echo $check if [ $check -ge 5 ...
2
votes
3answers
44 views

Looking for a way turn multiples commands with same parameter into a one liner

I sometimes end up doing things like: Example: from ~/blah $ mkdir ~/test-tmp $ cp * ~/test-tmp $ cd ~/test-tmp using the destination dir 3 times in a row. Isn't there a way to turn these into a ...
4
votes
1answer
37 views

What exactly is 'scrollback' and 'scrollback buffer'?

What are "scrollback" and "scrollback buffer" in programs like bash and screen, and how do they relate to the tty, the programs being run, and stdin/ stdout/ stderr? Here is the only definition of ...
6
votes
2answers
277 views

How to find out which program can open a given file?

Let's say I have a file thesis.pdf or picture.jpg Is there a command which returns a program to open this file with? I am aware of the command file, but it just returns the correct type of the file ...
1
vote
3answers
79 views

How do I Copy and Paste lines between a start and end keyword?

I have two text files, and I want to copy a bunch of lines from one to the other. File one has a list of packages, and I want to copy it to list two. This list of packages isn't at the start of file ...
4
votes
2answers
62 views

How to redirect stdout to a file and read from the same file simultaneously with another task?

I want to run a task (which takes quite a long time) remotely in Ubuntu Linux Bash via nohup and redirect stdout to a file, e.g.: nohup task > out.txt & From time to time I would like to ...
2
votes
1answer
43 views

Backslash with pipe in system command from awk

I want to invoke shell command from awk so I am using system() but when I am passing expression in I am getting error at backslash. Here is my expression echo "select * from abc limit 1;"| ...
0
votes
2answers
23 views

concatenate .out files

Can I combined multiple .out files with the cat command in bash or csh? Additionally I want only the header of first file to be concatenated and I was thinking of using the tail function for that. ...
2
votes
3answers
182 views

Shell script not executing

Not sure what is happening. Lets call script a.sh with the following /users/guru$ cat a.sh #! /usr/bin/ksh echo "Hello" date Execute with ksh. It gets done. /users/guru$ ksh a.sh Hello Tue Jul ...
0
votes
1answer
62 views

Bash script question - skip enter key press [duplicate]

Here is a portion of my script: read main_menu case "$main_menu" in "0" ) exit ;; "1" ) cp /etc/bamt/cgminer.conf.X11 /etc/bamt/cgminer.conf; sudo mine restart; ...
3
votes
2answers
103 views

Add arguments to bash -c

Let say that I want to run a command through bash like this: /bin/bash -c "ls -l" According to bash man page, I could also run it like this: # don't process arguments after this one ...
1
vote
1answer
36 views

Bundling of dependencies with shell scripts

Shell scripts often have to depend on tools that may not be installed on the users' computer. To circumvent this problem, many scripts have multiple fallbacks. IMO doing such things only leads to ...
3
votes
2answers
88 views

Get specific line from command output in awk

I have used pipeline to read specific record from impala shell.Here is what I got [cloudera@localhost ~]$ echo "select * from abc where key > 'a-26052014015400' limit 1;" | impala-shell Starting ...
14
votes
1answer
846 views

What does the @ (at) symbol before a filename mean in a curl command?

I am looking at an example of a curl command that uses the @ symbol before the filename to post data to the server. curl http://localhost/ --data-binary @file.txt What does this mean? Does it ...
4
votes
3answers
80 views

Write text messages between Unix and Windows

Is it possible to send text messages between two users of the same LAN, but the first running Windows with cmd and the second running Linux/Unix? I am not looking for an instant messaging service. I ...
4
votes
1answer
136 views

Keep getting the same result after “export PATH”

I am doing this: $ which cabal /usr/bin/cabal $ export PATH=$PATH:$HOME/.cabal/bin $ which cabal /usr/bin/cabal I expect to get /.cabal/bin/cabal for $ which cabal (this path exists) after this. ...
3
votes
2answers
56 views

Getting the current path in .desktop EXEC command

Im trying to make a .desktop file run a .sh which is stored in the same directory as the .desktop. The whole directory needs to be portable and moved from machine to machine. my run script is run.sh ...
2
votes
2answers
109 views

How to force watch to run under bash

The problem is that when watch is executed it runs sh and I get this error: sh: 1: func1: not found here is the code: #!/bin/bash func1(){ echo $1 } export -f func1 watch func1
3
votes
1answer
58 views

find files without extension

Let say I have: foo.txt bar baz.ooo If I use ls -1 !(*.*) then I'll get only bar on the output. Great, now I wish to have same results with find - some find -regex that will do the job. NOTE: ...
0
votes
0answers
22 views

How to return multiple select count in an array variable in shell

I have a 4 SQL count values which I want to return in an array record_count so that I can use that count values in some if statements later in the shell program. But I am not able to return the values ...
0
votes
0answers
14 views

command type “hashed”? [duplicate]

type displays information about a command's type. How would it be interpreted if used as a command name? What command "types" are there? In the following example, what does "hashed" mean? Is it ...
0
votes
1answer
39 views

What is “built-in” command in bash [duplicate]

cd is a built-in command in Bash. Is a built-in command or function in Bash the same concept as a built-in command or function in an interpreter language (e.g. Python)? Is "built-in" a concept of ...
1
vote
3answers
75 views

Problem when splitting command with backslash in unix prompt

I often use the space-backslash combination ( ) to split a command and its parameters into various lines and make it more readable: /home/user> ls -ltra \ > file1.txt \ > file2.txt ...
1
vote
1answer
19 views

svn: add all my new files and directories

I'm using Solaris 10. I need to add to SVN everything I've placed in the sub directories of my SVN checkout. I have added files and directories and sub directories - is there a command to take care of ...
7
votes
4answers
666 views

What is the source of help?

help displays information about builtin commands. What is the source of help? Does it maintain a database for builtin commands, or does it read some files of each builtin commands (similar to the ...
1
vote
1answer
23 views

How to slice a text file into several files of 100 lines each? [duplicate]

My question might be quite unclear here. I have a giant text file with values that looks like this 0.00601233 0.000139403 0.000133679 0.000139497 0.000141683 0.000141888 0.000138646 0.000133465 ...
3
votes
1answer
30 views

Why does the read command not take interactive options when run by sh?

I want to download a provisioning script that reads some configuration parameters via read, and execute it: curl http://example.com/provisioning.sh | sh The problem is, that the read command in the ...
1
vote
2answers
35 views

what's the right pattern to match my command

OS: AIX 7.1 I am working on a shell script which let user input some command and execute it, one of the commands is in this form: compile appname the appname only can be one of [ccms|asws], what's ...
0
votes
1answer
50 views

What is the difference between ~ and / in paths [duplicate]

When I first log in to Unix on my Mac, I usually see a ~ after my username in the command line. However, if I look at the apps contained in that directory ~/Applications they are not all of my ...
10
votes
3answers
594 views

Is there any major difference when comparing a variable as a string or as an int

Out of curiosity, when doing a bash variable comparison (its value being an integer) it's possible to test it against some predefined value either declared as an int or as a string. Sample script: ...
2
votes
1answer
28 views

setenv not working in tcsh

I am trying to install a program on my brand-new CentOs. The installation requires setenv, which apparently does not work, not even in the tcsh shell. Can anyone give me some advice? [Anna@anna ...
1
vote
1answer
55 views

How to run java service as a non-root user on CentOs 6

I have a script that starts a Java application as a service on CentOS 6: #!/bin/sh # chkconfig: - 80 20 SERVICE_NAME=cn4server PATH_TO_JAR=/usr/local/share/myserver/cn4server.jar ...
3
votes
1answer
21 views

annotate “include” file for grep with comments?

I do a grep sort that includes certain strings. That is, give me the lines in a file that DO contain certain strings. As in grep -fv include file > out That command looks in file and sends to ...
4
votes
1answer
40 views

How to update 'command cache' after change of soft links?

I have changed multiple soft links on my system with ln -f -s. When I view the link with ls -l, I see they point to the right target. However, when I try to run the command, it still tries to use the ...
6
votes
3answers
241 views

`/proc/$PID/cwd` : is there a POSIX equivalent?

Linux has a /proc directory and file‑system, which as far as I can tell, is not part of POSIX. In each /proc/$PID subdirectories, is a symbolic link, cwd, pointing to the actual working directory of ...
0
votes
0answers
24 views

Virtual serial port problem

Background: I've to test external GSM module, connected to PC with serial port. Since I'll have to either send messages both to do more, I need to create two virtual serial port (script provided by ...
4
votes
4answers
268 views

what does $* mean in shell [duplicate]

What does $* mean in shell? I have code two function, run_command and run_test, they are called like this: if [ -n "`echo ${GOAT_COMMANDS} | grep $1`" ]; then run_command $* else run_test $* fi ...
4
votes
1answer
50 views

Is it possible to put arithmetic expressions in a crontab?

I know I can do simple arithmetic in shell scripts, like so: #!/bin/bash ((sum = 1 + 2)) echo sum This will output 3 on execution. My question now is, can this kind of expressions be used in ...
2
votes
0answers
19 views

Running Custom commands in a Terminal Application [duplicate]

I'm running a terminal application in /dev/pts/X terminal that has its own console as:         What I need is to run commands specific to this application but from ...
8
votes
2answers
187 views

Redirecting output depending on grep regex

I am using gradle run to start a REST server. The output of the REST server looks like this: XXX.XXX.XX.XXX - <moreinfo> randomtext randomtext XXX.XXX.XX.XXX - <moreinfo> XXX.XXX.XX.XXX - ...
5
votes
1answer
163 views

Test -n gives unexpected result

I understand test -n <expression> to return false if the expression evaluates to a string length of greater than 0. Why then does the following happen? Macbook:~ echo ${#undeclared_variable} 0 ...
2
votes
2answers
38 views

how to filteri by asterisk or similar expression by rsync in zsh

I have a lot of files named like: /var/log/foo/2014-07-06-01.log ... /var/log/foo/2014-07-20-04.log Everyday I have several log files and I want to download specified day's log files: $ rsync ...
5
votes
2answers
151 views

How to zip a file and save it in another directory

How can I zip a file and save it in another directory using the command line? I have no space left in directory (100% full).
5
votes
2answers
217 views

Is it possible to use shell parameter variables ($1, …, $@) directly in CLI?

Sometimes it is necessary to emulate and verify the above variables in small examples and then can be copied immediately to some script, etc. I tried to solve by using a simple example in the ...
3
votes
4answers
65 views

Generate random numbers in specific range

After googling a bit I couldn't find a simple way to generate with a shell command a random number included in a specific range, between a minimum and a maximum. I read about /dev/random, ...
3
votes
1answer
47 views

Using inotify to monitor a directory but not working 100%

I have written a bash script to monitor a particular directory /root/secondfolder/: #!/bin/sh while inotifywait -mr -e close_write "/root/secondfolder/" do echo "close_write" done When I ...
2
votes
1answer
68 views

Accumulate Filename in a Log file using shell script

I have files with their names as ABC_-_123321.20140505_-_161500.CSV ABC_-_654145.20140506_-_135020.CSV String_-_SerialID.Date_-_Time.CSV StartDate, StartTime, EndDate and EndTime are given as ...
3
votes
1answer
49 views

redirect output for a command that takes in multiple arguments

this command is to redirect output of time to with multiple args: $ time wc test >wc.out 2>time.out unix programming environment book shows that the error output of time redirects to ...
1
vote
1answer
42 views

How to enclose a quoted variable in quotes

I want to call: ./mjpg_streamer -i "./input_uvc.so -r 320x240" -o "./output_http.so -w ./www" from a C program, running system(). The problem is that I have to enclose shell command in quotes, which ...
7
votes
3answers
683 views

Why do some commands not read from their standard input?

I wonder what when we should use pipeline and when we shouldn't. Say for instance, to kill certain process which handling pdf files, the following will not work by using pipeline: ps aux | grep pdf ...