unix

ternary construction not equivalent with if then else

大憨熊 提交于 2020-01-30 08:48:05
问题 The following if/then test (in bash): if [ 1 ]; then ls /undef_dummy > /dev/null 2>&1; else echo "else stmt"; fi seems not equivalent to its ternary version: (test 1) && ls /undef_dummy > /dev/null 2>&1 || echo "else stmt" The first one will print nothing but the second one will print "else stmt". This is because the || operator in the ternary version relates to the return status of either the test or the command executed if the test passes. But usually, we want the else statement to only

How to iterate over text file having multiple-words-per-line using shell script?

北战南征 提交于 2020-01-30 08:30:25
问题 I know how to iterate over lines of text when the text file has contents as below: abc pqr xyz However, what if the contents of my text file are as below, abc xyz cdf pqr lmn rst and I need to get values "abc" stored to one variable and"xyz" stored to another variable. How would I do that? 回答1: If the delimiter is a space then you can do: #!/bin/bash ALLVALUES=() while read line do ALLVALUES+=( $line ) done < "/path/to/your/file" So after, you can just reference an element by ${ALLVALUES[0]}

How to iterate over text file having multiple-words-per-line using shell script?

∥☆過路亽.° 提交于 2020-01-30 08:30:25
问题 I know how to iterate over lines of text when the text file has contents as below: abc pqr xyz However, what if the contents of my text file are as below, abc xyz cdf pqr lmn rst and I need to get values "abc" stored to one variable and"xyz" stored to another variable. How would I do that? 回答1: If the delimiter is a space then you can do: #!/bin/bash ALLVALUES=() while read line do ALLVALUES+=( $line ) done < "/path/to/your/file" So after, you can just reference an element by ${ALLVALUES[0]}

Walking a Linux/Unix filesystem with Java?

自古美人都是妖i 提交于 2020-01-30 08:21:07
问题 I need to create a Java util that will recurse its way through a Unix (and/or Linux) filesystem and build an object model of the directory structure, retrieve file info - size, created date, last accessed date etc - plus I need to retrieve info on the physical storage device the files are sitting on. Ideally, this util will be portable. I have no experience of the Java standard libraries and only limited experience of Unix OS. Are there Java standard libraries that will handle working with

Walking a Linux/Unix filesystem with Java?

二次信任 提交于 2020-01-30 08:19:45
问题 I need to create a Java util that will recurse its way through a Unix (and/or Linux) filesystem and build an object model of the directory structure, retrieve file info - size, created date, last accessed date etc - plus I need to retrieve info on the physical storage device the files are sitting on. Ideally, this util will be portable. I have no experience of the Java standard libraries and only limited experience of Unix OS. Are there Java standard libraries that will handle working with

jsch-->Not able to connect from unix jump server to another unix servers using java

倖福魔咒の 提交于 2020-01-30 08:13:28
问题 I am not able to connect secured server one unix server to another unix server.From putty by ssh i am able to connect easily but i am geeting below error when connet from jsch. successful putty Steps->connect server1 in putty->on successful->Connect server2 using "ssh user@ip" jsch steps--> Connected session1-->one server connected //comment-->running command on server 1 to connect other server Error:- Pseudo-terminal will not be allocated because stdin is not a terminal. Permission denied,

jsch-->Not able to connect from unix jump server to another unix servers using java

只愿长相守 提交于 2020-01-30 08:12:45
问题 I am not able to connect secured server one unix server to another unix server.From putty by ssh i am able to connect easily but i am geeting below error when connet from jsch. successful putty Steps->connect server1 in putty->on successful->Connect server2 using "ssh user@ip" jsch steps--> Connected session1-->one server connected //comment-->running command on server 1 to connect other server Error:- Pseudo-terminal will not be allocated because stdin is not a terminal. Permission denied,

How do i get last sunday date from a given date in unix

限于喜欢 提交于 2020-01-30 08:02:44
问题 get last sunday date as output from a given date (not current date) as input Example input: 08-30-2017 (%m-%d-%Y) output should be last sunday: 08-27-2017 === All of the below commands use current day as reference .But i want to give the reference date as input to get last sunday. Please help me with the command. date +%m-%d-%Y -d "2017-09-10 -7 days" date +%m-%d-%Y -d "last Sun" 回答1: If you deal with a fixed date format %m-%d-%Y , it should be transformed to %Y-%m-%d format to be processed

Submitting code on CodeEval site

时间秒杀一切 提交于 2020-01-30 05:41:26
问题 A Java program on CodeEval had to accept a file path as an argument. I used a command line argument to do this, but I get an exception as below when I submitted my code on CodeEval. What are some potential solutions to this problem? Exception in thread "main" java.util.NoSuchElementException at java.util.StringTokenizer.nextToken(StringTokenizer.java:349) at java.util.StringTokenizer.nextElement(StringTokenizer.java:407) at Main.FileRead(Main.java:61) at Main.main(Main.java:26) 回答1: Here's

Using variables as part of variable name in unix [duplicate]

旧城冷巷雨未停 提交于 2020-01-30 05:00:31
问题 This question already has answers here : How can I generate new variable names on the fly in a shell script? (5 answers) Creating a string variable name from the value of another string (3 answers) Closed 5 years ago . I want to name variable as a_${v} . for example : v can be 2013 2014 I am now declaring a variable to a_${v} a_${v}=hI # a_2013 should be Hi v=2014 so a_${v}=Hello # a_2014 should be Hello I tried using eval command though it is not throwing error while assigning a value but I