我在这里按照教程:http://bash.cyberciti.biz/guide/If..else..fi#Number_Testing_Script
我的脚本看起来像:
lines=`wc -l $var/customize/script.php`
if test $lines -le 10
then
echo "script has less than 10 lines"
else
echo "script has more than 10 lines"
fi
Run Code Online (Sandbox Code Playgroud)
但我的输出看起来像:
./boot.sh: line 33: test: too many arguments
script has more than 10 lines
Run Code Online (Sandbox Code Playgroud)
为什么说我有太多的论点?我没有看到我的脚本与教程中的脚本有何不同.
我想看看变量是否在一系列值之间,例如,如果x介于20和30之间,则返回true.
最快的方法是什么(使用任何基于C语言)?
显然可以用for循环完成:
function inRange(x, lowerbound, upperbound)
{
for(i = lowerbound; i < upperbound; i++)
{
if(x == i) return TRUE;
else return FALSE;
}
}
//in the program
if(inRange(x, 20, 30))
//do stuff
Run Code Online (Sandbox Code Playgroud)
但是这样做的可怕的繁琐if(inRange(x, 20, 30))是比没有使用内置函数的逻辑更简单吗?
我做了一个简单的课来代表一扇门.要返回变量,我用this指针访问它们.关于只是访问变量,使用this指针访问它们之间的区别是什么?
class Door
{
protected:
bool shut; // true if shut, false if not shut
public:
Door(); // Constructs a shut door.
bool isOpen(); // Is the door open?
void Open(); // Opens the door, if possible. By default it
// is always possible to open a generic door.
void Close(); // Shuts the door.
};
Door::Door()
{}
bool Door::isOpen()
{
return this->shut;
}
void Door::Open()
{
this->shut = false;
}
void Door::Close()
{
if(this->isOpen()) this->shut …Run Code Online (Sandbox Code Playgroud) 我有<div class="animate">和在css:
div.animate:hover{
//do stuff
}
Run Code Online (Sandbox Code Playgroud)
但是也想通过javascript调用它.
可能吗?
我有一个大的日志文件,我希望能够从文件中的位置X显示100行.我需要使用fseek而不是file()因为日志文件太大.
我有一个类似的功能,但它只会从文件的末尾读取.如何修改以便也可以指定起始位置?我还需要从文件的末尾开始.
function read_line($filename, $lines, $revers = false)
{
$offset = -1;
$i = 0;
$fp = @fopen($filename, "r");
while( $lines && fseek($fp, $offset, SEEK_END) >= 0 ) {
$c = fgetc($fp);
if($c == "\n" || $c == "\r"){
$lines--;
if($revers){
$read[$i] = strrev($read[$i]);
$i++;
}
}
if($revers) $read[$i] .= $c;
else $read .= $c;
$offset--;
}
fclose ($fp);
if($revers){
if($read[$i] == "\n" || $read[$i] == "\r")
array_pop($read);
else $read[$i] = strrev($read[$i]);
return implode('',$read); …Run Code Online (Sandbox Code Playgroud) 我理解15 mod 5 = 0因为没有来自师的余数.
但为什么15.5 mod 5 == 0呢?还没有.5剩下的?
$time = "15.5";
$interval = 5.0;
if($time % $interval == 0)
echo "it's time!";
else
echo "not time";
//Outputs: it's time!
Run Code Online (Sandbox Code Playgroud) 我有一堆HTML代码,我想删除所有的HTML标记.
我认为这可以使用Regex(正则表达式).通过搜索和替换,我该怎么做?
我试过<*>,我认为*是一个通配符,但显然不是.我如何让正则表达式找到所有的
<text>?
有时,从我的电子邮件中复制粘贴代码会使一切都有一个额外的空白行.
例如
1: hi
2:
3: hello
4:
Run Code Online (Sandbox Code Playgroud)
有没有办法用正则表达式来定位这些空行并删除它们?我正在使用notepad ++进行搜索(使用正则表达式)并替换功能.
我有一个看起来像这样的文件(带有换行符和奇怪的间距):
Player: Alive: Score: Ping: Member of Team:
player1 No 16 69 dogs
bug Yes 2 63 insects
name with space No 0 69 cats
bob No 0 69 dogs
Run Code Online (Sandbox Code Playgroud)
如何抓住第一列并将其转换为数组?
期望的输出:
$ players [1] ---->"player1"
$ players [2] ---->"bug"
$ players [3] ---->"with space with space"
$ players [4] - --->"鲍勃"
我有一个从降序排列的数字.当我添加到这个数组时,我添加到最后然后再做natsort($times).$ times然后看起来像这样(由print_r获得):
Array
(
[0] => 0.01
[1] => 0.02
[2] => 0.05
[3] => 0.08
[7] => 0.10 <-- Just added and natsorted
[4] => 0.11
[5] => 0.14
[6] => 0.21
)
Run Code Online (Sandbox Code Playgroud)
但是,我希望重新分配所有键,以便刚刚添加的0.10是数组索引4,这样可以很容易地看到新时间的位置.即"你的排名是$ arrayindex + 1"
除了将整个数组复制到新数组中以获取新密钥外,还有更好的方法吗?