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)

0
votes
1answer
7 views

SHELL— Date format validation

How can I check whether the format of date is correct without date command being printed? date -d $datum +"%Y-%m-%d" if [ $? -ne 0 ] ;then echo error exit fi
0
votes
2answers
34 views

What is the variable of $#?

I'm learning introductory Linux and came across something which I did not understand: "The following command has been executed: set 10 20 30 40 50 Enter the value of the variable $#: I understand ...
-4
votes
0answers
14 views

BASH— after getopts continues after exit [on hold]

in getopts(probably) it has two functions in it. One of them has exit at the end and there is also exit at the end of the option b. When I call it like this: ./name.sh -b. (without required argument) ...
1
vote
0answers
20 views

How do processes, jobs and session relate to each other ? [duplicate]

Could you deliver an answer in a way that does not require too much special knowledge in advance, yet also deliver some deeper insight to a lesser advanced Linux User ?
0
votes
1answer
41 views

Shell— print only certain lines from output

I need to choose from output only lines where number is bigger than chosen number. For example x=27 and I need to find only lines where the number in first column is bigger than that x. In this ...
1
vote
1answer
26 views

How to run a long running grep, pipe the result into less and put everything into background?

I often find myself in the situation where I need to find a code base for a given symbol like so: find src/galio -not -path './src/stapi-sdk/apilib/* -regextype posix-extended -iregex ...
0
votes
0answers
36 views

Shell splitting line into words without temporary file

yesterday I found out that this creates temporary file. Can anyone help me how to rewrite it so it wouldn't? I am desperate I have tried everything that I know, but it doesn't want to work. And also I ...
3
votes
3answers
55 views

Shell test to find a pattern in a string

I just wanted to ask whether there is any command which would work on common shells (bash, dash, kornshell)? It is supposed to check if the line variable contains any part of the path. if [[ $line =~ ...
-1
votes
2answers
56 views

Why doesn't “rm -rf ./” delete anything?

The command rm -rf ./ does not do anything in a directory full of sub directories and files. Why so? Isn't -r supposed to go recursive? To add more confusion, it even prints an error message ...
2
votes
2answers
54 views

Print file contents and delete the printed content* from the file

In Linux, from a bash shell, how can I print the contents of a file and remove the content I just printed content from the file? I have a program writing texts to a file repeatedly. On a Linux shell ...
3
votes
1answer
22 views

Trailing colons and dash's builtin test command

What's the meaning of a trailing colon to dash's builtin test (or [) command? I was surprised when I found that if [ ... ]: ; then .. ; fi works (at all) in dash, but not bash, and it seems to be ...
-3
votes
0answers
33 views

Convert file pattern in Unix

I have a file with content as below 31/01/2014 1234 2234 4567 3321 ...n Need to write a shell script to convert the above file as below: DD_Date='31/01/2014' ...
19
votes
7answers
869 views

`command .*` acts on the parent directory

Someone of our team wanted to recursively change the user permissions on all hidden directories in a users home directory. To do so he executed the following command: cd /home/username chown -R ...
0
votes
1answer
48 views

can we get sorted grep output

I have same: 1.txt with apple written in it, 2.txt with mango written in it, 3.txt with apple written in it, 4.txt with mango written in it. grep -e apple -e mango *.txt will give result as: 1.txt: ...
6
votes
1answer
762 views

What is the meaning of 'ln -sf' in Linux?

I have 2 questions. First one is for the -sf options and second one is for the more specific usage of -f options. By googling, I figured out the description of command ln, option -s and -f. (copy ...
2
votes
3answers
52 views

What happens if I pass too few parameters to a shell function?

I would like to ask about passing parameters into functions. I tried this: function_name $var1 $var2 but usually (sometimes it printed error) it didn't make any difference whether I passed them or ...
2
votes
3answers
35 views

Command substitutions vs backslash escapes in a quoted string

Consider a double-quoted command substitution with backslash escapes inside it, like this: echo "$(echo '\\')" It prints out \\, whereas I would have expected it to print out only one backslash. My ...
0
votes
1answer
27 views

How do i write a shell script so that when i compile my c++ program it will put the binary into the Binary Directory

I have a directory called Binary and bunch of source files: ./ ├── Binary/ ├── lesson02.cpp ├── lesson04.cpp └── lesson06.cpp when I compile the source code g++ lesson01.cpp -o lesson01 I want ...
1
vote
2answers
41 views

Remove paragraph from file

I have a file (file.php) like this: ... Match user foo ChrootDirectory /NAS/foo.info/ ForceCommand internal-sftp AllowTcpForwarding no GatewayPorts no ...
1
vote
1answer
53 views

Brace expansion not working in a script

for i in {1..40} do echo $i done I got {1..40} and I would like to have something like 1 2 3 and so on so I can use the variable i inside a command's parameter.
1
vote
1answer
18 views

Switch-case block inside define keyword in a single logical line in a makefile

This is the code excerpt from ghc.mk, part of Haskell source compilation. I find it different, because the author has chosen to write one function block in a single line. Is it a common practice in ...
0
votes
4answers
60 views

Copy same specific parts of a file to another file

How can I copy same specific parts of a file to another file? In the first file, I have: user01: Id name nationality user02: Id name nationality . . . I want to copy each piece of information to a ...
2
votes
1answer
36 views

How to verify the target of a symbolic link points toward a particular path

Within a bash script, I know I can check if a file is a symbolic link with the following syntax if [ -L $path ] Does any one know how I would test if that path was linked to a particular path? E.g. ...
0
votes
0answers
29 views

How to get and print a user's public IP address in a Shell Script? [duplicate]

I've just completed a lengthy installation script that deploys a Ruby on Rails application unto web servers. At the end of this script, I'd like it to print something along the lines of: "Installation ...
-1
votes
1answer
30 views

Mutiple commands after sudo in one line

I want to execute multiple commands after a sudo command su - appuser -c "cd /apps/bundle/bundle-client/bin ; export BDL_WEB_USER=not_used ; export BDL_WEB_PASSWORD=not_used ; ./bundle -b ...
1
vote
1answer
31 views

Search for text inside java command output

I have a folder which have multiple Jar files. * dummy.jar * myjar-xx.jar * myjar-yy.jar Using find, I need to find first file starting with "myjar" Now, I want to grep the contents of ...
4
votes
1answer
46 views

Why does 'jobs' always return a line for finished processes when run in a subshell within a script?

Normally, when a job is launched in the background, jobs will report that it is finished the first time it is run after the job's completion, and nothing for subsequent executions: $ ping -c 4 ...
1
vote
1answer
30 views

How do I run a program without network access? [duplicate]

I am making a program that scrapes information from some web services. I want to test how my program reacts when it can't reach the web service, like if the web service is down or if the local ...
2
votes
0answers
28 views

Is there a nice way to set directory/project local environment variables?

I have been working on several projects and they require different environment variables (e.g., PATH for different versions of clang executables, PYTHONPATH for several external modules). Whenever I ...
3
votes
2answers
40 views

Shell globbing without matching files

I frequently make use of shell file name globbing to do things like operate on all of /dev/sda, /dev/sdb, /dev/sdc, etc by doing /dev/sd[a-f], however, this relies on there being files on disk that ...
1
vote
1answer
43 views

Printf formatting with variable format - what does this var reference?

I am experimenting with printf formatting in bash and I ran across this piece of code: #/bin/bash divider=============================== divider=$divider$divider header="\n %-15s %8s %10s %11s\n" ...
0
votes
1answer
38 views

What's a way to get the first network interface using grep in ifconfig? [on hold]

Just trying to figure this out for a System Administration introduction course, and I can't seem to get it.
1
vote
4answers
77 views

How do I suppress error messages from cp?

I am currently looking ways to suppress error command in Linux, in particular, the command cp. I do: root@ubuntu:~$ cp /srv/ftp/201*/wha*/*.jj ~/. cp: cannot stat `/srv/ftp/201*/wha*/*.jj': No ...
0
votes
0answers
29 views

Restrict FTP user to access only its own directory and Download Only

I need to create a user which can only FTP to specific directory and download data from it only no upload or delete files. After searching on line I reached to following points useradd -g 10 -d ...
-1
votes
0answers
41 views

No Such file or Directory 4 [on hold]

throw the script posted in this question link syntax error near unexpected token `)' I get this error: test.txt: No such file or directory 140308719470240:error:02001002:system library:fopen:No ...
0
votes
1answer
43 views

Can a command in a shell pipeline determine the tty characteristics of its context?

I have a bash script that columnizes a list of items. By default it will guess at the number of columns to output, based on the terminal width as reported by stty size. But when the script is in a ...
1
vote
1answer
152 views

how to check the string is Null or not in shell script? [on hold]

I had a script like this #!/bin/bash line="hello" if [ -z $line ] ; then echo "String null" fi This will work properly, but when I give the lineas follows ...
1
vote
2answers
65 views

Can brace expansion be performed within the `at` command?

In bash, brace expansion is performed as a shell operation before executing the command.1 This means the following will work: echo {1..10} >output | at -m now The output will be 1 2 3 4 5 6 7 8 9 ...
0
votes
1answer
25 views

Glob pattern argument for echo command

echo *.c in bash, treats the argument as a constant and prints *.c. How to force it to consider it as a glob pattern and print the list of files/folders ending with .c?
4
votes
2answers
54 views

Coming back to a command I have partially written [duplicate]

Often I find myself partway through writing a long command (or chain of commands) and realise I need to run another command before I can finish typing out this current one. Examples Sometimes, I... ...
2
votes
1answer
26 views

Is there a way to suspend an process belongs to shell A and foreground it in shell B?

I knew how to suspend one process and bring it into foreground in current shell, but I have no idea about that If I have run a process in shell A and now I want to bring it into foreground in current ...
1
vote
2answers
207 views

Why do I have double slash here?

$ which mycommand /home/t/program_files/document/other edits//mycommand Why do I have double slash // here?
1
vote
1answer
31 views

Using parameters in a script

I usually use the find command to automatically copy certain multimedia files from directory A to directory B. I use the following command: for f in `find ./ -name "*.mkv" -mtime -24h`; do cp $f ...
2
votes
1answer
232 views

alias -g '${1+“$@”}'='“$@”', what does it do?

Most makefile have this strange set of symbols '${1+"$@"}'. $@ is the makefile target filename. But why does, people try to use the complex symbol like '${1+"$@"}'?
0
votes
1answer
48 views

Double quotes in bash

I am trying to create a bash file which calls a program that expects a parameter to submitted between two double quotes. Take a look at my file content. #!/bin/bash echo ./yowsup/yowsup-cli demos ...
0
votes
2answers
34 views

how to delete file that start with “-” [duplicate]

I try to delete this file on my solaris machine rm "-Insi" rm: illegal option -- I rm: illegal option -- n rm: illegal option -- s I also try this rm "\-Insi" -Insi: No such file or directory ...
0
votes
1answer
38 views

What is the logic behind the expression cat > foo << “wordofchoice” [duplicate]

I know the > and >> operators, > puts something into a file by deleting the old content, >> appends something onto the end of the file's content. When I only use cat > foo I am able to write ...
5
votes
4answers
229 views

How to put a newline special character into a file using the echo command and redirection operator?

I would like to create a file by using the echo command and the redirection operator, the file should be made of a few lines. I tried to include a newline by "\n" inside the string: echo "first ...
0
votes
0answers
12 views

How to convert Ubuntu init script to Amazon Linux AMI init script?

I had a Ubuntu based Amazon EC2 server where I was running my java based application. For this I had written a init script which was running perfectly and as follows #! /bin/sh # set the environment ...
0
votes
1answer
30 views

Exporting a piped command without evaluating output?

I'm trying to set an export that would effectively kill a process based on the PID that pgrep feeds it. Running the command kill $(pgrep myAppName) appears to work (if 'myAppName' were the name of an ...